From 6a345316dffadcfe0cb3e9d357f0adff3c49f706 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sat, 17 Nov 2012 18:06:23 -0800 Subject: [PATCH] if labels, don't allow set collapse for a : A # X | B ; --- CHANGES.txt | 2 ++ tool/playground/T.g | 7 ++++++- tool/src/org/antlr/v4/parse/BlockSetTransformer.g | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5700ed144..4c8f945d4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/tool/playground/T.g b/tool/playground/T.g index 0b958ddc1..129d86b9c 100644 --- a/tool/playground/T.g +++ b/tool/playground/T.g @@ -1,3 +1,8 @@ grammar T; -s : EOF ; +s : A # X + | B + ; +b : A # Y + | B{} + ; diff --git a/tool/src/org/antlr/v4/parse/BlockSetTransformer.g b/tool/src/org/antlr/v4/parse/BlockSetTransformer.g index 7862f009b..d5cf6607c 100644 --- a/tool/src/org/antlr/v4/parse/BlockSetTransformer.g +++ b/tool/src/org/antlr/v4/parse/BlockSetTransformer.g @@ -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[$BLOCK.token] ^(ALT[$BLOCK.token,"ALT"] ^(SET[$BLOCK.token, "SET"] setElement+))) | {!inContext("RULE")}? // if not rule block and > 1 alt ^(BLOCK ^(ALT setElement[inLexer]) ( ^(ALT setElement[inLexer]) )+)