if labels, don't allow set collapse for

a : A # X | B ;
This commit is contained in:
Terence Parr 2012-11-17 18:06:23 -08:00
parent 80b1fa7acb
commit 6a345316df
3 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,8 @@ November 17, 2012
* .tokens files goes in output dir like parser file.
* added check: action in lexer rules must be last element of outermost alt
* properly check for grammar/filename difference
* if labels, don't allow set collapse for
a : A # X | B ;
November 11, 2012

View File

@ -1,3 +1,8 @@
grammar T;
s : EOF ;
s : A # X
| B
;
b : A # Y
| B{}
;

View File

@ -65,7 +65,7 @@ boolean inLexer = Character.isUpperCase(currentRuleName.charAt(0));
GrammarTransformPipeline.setGrammarPtr(g, $tree);
}
: {inContext("RULE")}? // top-level: rule block and > 1 alt
^(BLOCK ^(ALT setElement[inLexer]) ( ^(ALT setElement[inLexer]) )+)
^(BLOCK ^(alt=ALT {((AltAST)$alt).altLabel==null}? 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]) )+)