01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: /**The context needed to add root,child elements to a Tree. There
09: * is only one alternative (i.e., a list of children). We subclass to
10: * specialize. MakeGrammar.addElementToCurrentAlt will work correctly
11: * now for either a block of alts or a Tree child list.
12: *
13: * The first time addAlternativeElement is called, it sets the root element
14: * rather than adding it to one of the alternative lists. Rather than have
15: * the grammar duplicate the rules for grammar atoms etc... we use the same
16: * grammar and same refToken behavior etc... We have to special case somewhere
17: * and here is where we do it.
18: */
19: class TreeBlockContext extends BlockContext {
20: protected boolean nextElementIsRoot = true;
21:
22: public void addAlternativeElement(AlternativeElement e) {
23: TreeElement tree = (TreeElement) block;
24: if (nextElementIsRoot) {
25: tree.root = (GrammarAtom) e;
26: nextElementIsRoot = false;
27: } else {
28: super.addAlternativeElement(e);
29: }
30: }
31: }
|