sets at top level work now: s : A | B ; in lexer and parser.
This commit is contained in:
parent
799b7afc1c
commit
64c050f233
|
@ -1,5 +1,6 @@
|
|||
grammar T;
|
||||
|
||||
s : (A | B) ;
|
||||
A : ('a'|'c');
|
||||
s : A | B ;
|
||||
x : (A|B);
|
||||
A : 'a'|'c';
|
||||
B : 'b' ;
|
||||
|
|
|
@ -64,7 +64,10 @@ boolean inLexer = Character.isUpperCase(currentRuleName.charAt(0));
|
|||
@after {
|
||||
GrammarTransformPipeline.setGrammarPtr(g, $tree);
|
||||
}
|
||||
: {!inContext("RULE")}? // if not rule block and > 1 alt
|
||||
: {inContext("RULE")}? // top-level: rule block and > 1 alt
|
||||
^(BLOCK ^(ALT setElement[inLexer]) ( ^(ALT setElement[inLexer]) )+)
|
||||
-> ^(BLOCK<BlockAST>[$BLOCK.token] ^(ALT<AltAST>[$BLOCK.token,"ALT"] ^(SET[$BLOCK.token, "SET"] setElement+)))
|
||||
| {!inContext("RULE")}? // if not rule block and > 1 alt
|
||||
^(BLOCK ^(ALT setElement[inLexer]) ( ^(ALT setElement[inLexer]) )+)
|
||||
-> ^(SET[$BLOCK.token, "SET"] setElement+)
|
||||
;
|
||||
|
|
|
@ -114,6 +114,7 @@ public class GrammarTransformPipeline {
|
|||
|
||||
/** Utility visitor that sets grammar ptr in each node */
|
||||
public static void setGrammarPtr(final Grammar g, GrammarAST tree) {
|
||||
if ( tree==null ) return;
|
||||
// ensure each node has pointer to surrounding grammar
|
||||
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
|
||||
v.visit(tree, new TreeVisitorAction() {
|
||||
|
|
|
@ -56,6 +56,7 @@ public class AltAST extends GrammarAST {
|
|||
public AltAST(Token t) { super(t); }
|
||||
public AltAST(int type) { super(type); }
|
||||
public AltAST(int type, Token t) { super(type, t); }
|
||||
public AltAST(int type, Token t, String text) { super(type,t,text); }
|
||||
|
||||
@Override
|
||||
public Tree dupNode() { return new AltAST(this); }
|
||||
|
|
Loading…
Reference in New Issue