Building Parsers with Java

sjm.examples.sling
Class FunctionAssembler

java.lang.Object
  |
  +--sjm.parse.Assembler
        |
        +--sjm.examples.sling.FunctionAssembler

public class FunctionAssembler
extends Assembler

This assembler uses information from a prototypical function object received in a constructor to guide the construction of a new function.

The constructor for this class requires a SlingFunction object that serves as a prototype. The prototype tells the type of function to assemble, and tells how many source functions this type needs. When this assembler works on an assembly, it will pop as many functions to use as sources as the number of sources in the prototype. This assembler will then create a copy of the prototype, will use the popped sources as the copy's source functions, and will push the copy.

For example, the constructor may receive a Cartesian object that has two source functions. When this assembler's workOn method executes, it will pop two functions from the stack, since the prototype function has two functions. This assembler will then create a fresh copy of the Cartesian prototype object, will use the popped functions as the copy's function sources, and will push the new copy.


Field Summary
protected  SlingFunction function
           
 
Constructor Summary
FunctionAssembler(SlingFunction function)
          Construct a new function assembler, using the provided function as a prototype.
 
Method Summary
 void workOn(Assembly a)
          Pop as many source functions as the prototype function has, create a fresh copy of the prototype using these sources, and push the copy.
 
Methods inherited from class sjm.parse.Assembler
elementsAbove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

function

protected SlingFunction function
Constructor Detail

FunctionAssembler

public FunctionAssembler(SlingFunction function)
Construct a new function assembler, using the provided function as a prototype.
Method Detail

workOn

public void workOn(Assembly a)
Pop as many source functions as the prototype function has, create a fresh copy of the prototype using these sources, and push the copy.
Overrides:
workOn in class Assembler
Parameters:
Assembly - the assembly to work on

by Steve Metsker