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