File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -428,7 +428,12 @@ def build_expr(node, parent_id):
428428 graph .add_edge (frm = parent_id , to = lambda_id )
429429 return
430430
431- for child in node .element () if isinstance (node , ANTLRv4Parser .AlternativeContext ) else node .lexerElements ().lexerElement ():
431+ children = node .element () if isinstance (node , ANTLRv4Parser .AlternativeContext ) else node .lexerElements ().lexerElement ()
432+ if isinstance (node , ANTLRv4Parser .LexerAltContext ) and not children :
433+ graph .add_edge (frm = parent_id , to = lambda_id )
434+ return
435+
436+ for child in children :
432437 build_expr (child , parent_id )
433438
434439 elif isinstance (node , (ANTLRv4Parser .ElementContext , ANTLRv4Parser .LexerElementContext )):
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2022 Renata Hodovan, Akos Kiss.
3+ *
4+ * Licensed under the BSD 3-Clause License
5+ * <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
6+ * This file may not be copied, modified, or distributed except
7+ * according to those terms.
8+ */
9+
10+ /*
11+ * This test checks whether the empty lexer and parser alternatives
12+ * are handled properly.
13+ */
14+
15+ // TEST-PROCESS: {grammar}.g4 -o {tmpdir}
16+ // TEST-GENERATE: {grammar}Generator.{grammar}Generator -r start -o {tmpdir}/{grammar}%d.txt
17+ // TEST-ANTLR: {grammar}.g4 -o {tmpdir}
18+ // TEST-PARSE: -p {grammar}Parser -l {grammar}Lexer -r start {tmpdir}/{grammar}%d.txt
19+
20+ grammar EmptyAlternatives;
21+
22+ start : | EMPTY ;
23+
24+ EMPTY : ' a' ( | ' b' ) ;
You can’t perform that action at this time.
0 commit comments