public class Annotator extends Visitor
Properties.FORMATTING property, indicating valuable
elements that need to be captured in the promise generated by
DirectLeftRecurser.
This visitor assumes that the entire grammar is contained in a
single module, that the grammar has been tokenized, and that
productions that may consume the input have been marked.Tokenizer,
Analyzer.consumesInput(Element)| Modifier and Type | Class and Description |
|---|---|
class |
Annotator.Detector
A visitor to detect whether productions need to be rewritten.
|
static class |
Annotator.Index
A mutable boxed integer.
|
static class |
Annotator.IndexPair
A pair of indices.
|
class |
Annotator.Rewriter
A visitor to rewrite productions.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<java.util.List<Binding>> |
after
The list of bindings for valuable elements after the regular,
bindable value, organized as a stack of copies.
|
protected Analyzer |
analyzer
The analyzer.
|
protected java.util.List<java.util.List<Binding>> |
before
The list of bindings for valuable elements before the regular,
bindable value, organized as a stack of copies.
|
protected java.util.List<Annotator.Index> |
elementIdx
The index of the regular, bindable value, organized as a stack of
copies.
|
protected boolean |
isGeneric
The flag for whether the current production is generic.
|
protected boolean |
isList
The flag for whether the current production is list-valued.
|
protected boolean |
isRecursive
The flag for whether the current production or sequence is
directly left-recursive.
|
protected boolean |
isTopLevel
The flag for whether the current choice is top-level.
|
static java.lang.String |
MARKER
The marker for synthetic variables.
|
protected Runtime |
runtime
The runtime.
|
protected java.util.List<Annotator.Index> |
sequenceIdx
The index of the sequence with the regular, bindable value,
organized as a stack of copies.
|
protected java.util.List<Sequence> |
sequences
The elements as a list of sequences.
|
protected int |
toProcessIdx
The index of the next sequence to process.
|
| Constructor and Description |
|---|
Annotator(Runtime runtime,
Analyzer analyzer)
Create a new annotator.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.util.List<Binding> |
after()
Get the current list of bindings after the regular value.
|
protected void |
annotate()
Process all elements in the current list of sequences.
|
protected java.util.List<Binding> |
before()
Get the current list of bindings before the regular value.
|
protected Binding |
bindAndVoid()
Bind and void the current regular, bindable element.
|
protected VoidedElement |
bindAndVoid(Element e)
Bind and void the specified element.
|
protected Annotator.Index |
elementIndex()
Get the current element index of the regular value.
|
protected boolean |
hasBindable()
Determine whether a bindable element has been processed.
|
protected boolean |
hasValuable()
Determine whether any valuable elements have been processed.
|
protected boolean |
isBoundAndVoided(Element e)
Determine whether the specified element already is bound and
voided.
|
static boolean |
isGeneric(FullProduction p)
Determine whether the specified production effectively is
generic.
|
static boolean |
isList(Type type)
Determine whether the specified type is a list type that can be
processed by this visitor.
|
protected boolean |
isParseTreeNode(Element e)
Determine whether the specified element is a possibly bound or
voided parse tree node.
|
static boolean |
isSingleRepetition(FullProduction p)
Determine whether the specified production recognizes only a
single repetition.
|
protected boolean |
isValuable(Element e)
Determine whether the specified element is valuable.
|
static boolean |
isValuable(FullProduction p)
Determine whether the specified production can have a semantic
value.
|
protected void |
pop()
Pop the top elements from the state for tracking bindable and
valuable elements.
|
protected void |
push()
Push a copy of the state for tracking bindable and valuable
elements.
|
protected void |
recurse(Element e)
Recursively process the specified element.
|
protected void |
reset()
Reset the current state for tracking bindable and valuable
elements.
|
protected Annotator.Index |
sequenceIndex()
Get the current sequence index of the regular value.
|
void |
visit(FullProduction p)
Visit the specified production.
|
void |
visit(Module m)
Visit the specified grammar.
|
void |
visit(OrderedChoice c)
Visit the specified choice.
|
void |
visit(Sequence s)
Visit the specified sequence.
|
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visitpublic static final java.lang.String MARKER
protected final Runtime runtime
protected final Analyzer analyzer
protected boolean isGeneric
protected boolean isList
protected boolean isRecursive
protected boolean isTopLevel
protected int toProcessIdx
protected java.util.List<Sequence> sequences
protected java.util.List<java.util.List<Binding>> before
toProcessIdxprotected java.util.List<Annotator.Index> sequenceIdx
toProcessIdxprotected java.util.List<Annotator.Index> elementIdx
toProcessIdxprotected java.util.List<java.util.List<Binding>> after
toProcessIdxprotected void push()
protected void pop()
protected void reset()
protected java.util.List<Binding> before()
protected Annotator.Index sequenceIndex()
protected Annotator.Index elementIndex()
protected java.util.List<Binding> after()
protected boolean isValuable(Element e)
true if the specified element has a semantic
value or can be rewritten to yield a semantic value. Rewriting
includes eliminating any voided element or converting a void
production into a production returning a semantic value.e - The element.true if the specified element is valuable.protected boolean isParseTreeNode(Element e)
e - The element.true if the specified element is a parse
tree node.protected boolean hasBindable()
true if a bindable element has been
processed.Analyzer.isBindable(Element)protected boolean hasValuable()
true if any valuable elements have been
processed.isValuable(Element)protected boolean isBoundAndVoided(Element e)
e - The element.true if the specified element already is
bound and voided.protected VoidedElement bindAndVoid(Element e)
e - The element.isValuable(Element)protected Binding bindAndVoid()
protected void annotate()
protected void recurse(Element e)
e - The element.public void visit(Module m)
public void visit(FullProduction p)
public void visit(OrderedChoice c)
public void visit(Sequence s)
public static boolean isGeneric(FullProduction p)
true if the specified
production is, in fact, generic or it is a void production that
also is non-lexical and consumes the input.p - The production.true if the specified production should be
treated as generic.Generifier.isGeneric(FullProduction)public static boolean isValuable(FullProduction p)
Properties.CONSUMER property.p - The production.true if the specified production can have a
semantic value.public static boolean isList(Type type)
type - The type.true if the specified type is a list type
that can be processed by this visitor.public static boolean isSingleRepetition(FullProduction p)
true if the
specified production returns a list of objects, nodes, generic
nodes, tokens, or strings and each alternative consists of only a
single, optionally bound repetition.p - The production.true if the specified production recognizes
only a single repetition.Copyright © 2014. All Rights Reserved.