public class TemplateWorker extends AbstractPatternWorker
patpath
. All template library filenames must end
in a suffix specified by TPL_SUFFIX
.
Each template is defined in the format required to be loaded using the
AstPersister
. Each valid template must be rooted at
an AstPersister.ELEM_ROOT
element.
A generic facility for text replacements is provided. This facility is
implemented after the reading of the elements from the XML file but
before those elements are converted into an AST subtree by the persister.
This allows any attribute in the same template to be customized on the fly
for different purposes. Since the persister translates everything from
its text form into a binary AST form, the result of these text
transformations is the same as if the original XML file had been hard
coded to the runtime values provided. Thus token types, token text and
other attritutes (even annotations) can be transformed in this manner.
Any replaceable text must be formatted with ${key}
where
a list of string-based key/value pairs are passed at runtime and are used
as the replacements for each matching key found. Note that the
${
and }
are only stored in the XML file, they
are not actually passed as part of the key in the replacements list.
This class also provides depot services to store and retrieve ASTs between rulesets that are disconnected in time and place (it still requires such sharing to occur within a single pattern engine run). For example, if a tree transformation requires a separation between the location at which an AST subtree is created and the location at which that subtree is attached, the subtree can be stored in the depot under a name and then retrieved 'downstream' in the same pattern engine run (the same pipeline). Please note that only 1 AST can be stored per name so this facility operates like a shared local variable pool of ASTs.
Modifier and Type | Class and Description |
---|---|
class |
TemplateWorker.Template
This is a pattern engine library that provides easy access to
libraries of pre-defined AST subtrees.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PEERNODE
Annotation name to mark a template node as the peer node.
|
static java.lang.String |
TPL_SUFFIX
Suffix for all template library filenames.
|
resolver
Constructor and Description |
---|
TemplateWorker()
Default constructor which calls the super constructor and registers
libraries with the pattern engine.
|
finish, getCopy, getLibrary, getSource, initialize, registerTree, resolveConstant, setLibrary, visitAst
public static final java.lang.String TPL_SUFFIX
public static final java.lang.String PEERNODE