Skip to content

Commit

Permalink
Fix the indexing of symbolic names of lexer rules in parser
Browse files Browse the repository at this point in the history
If a combined grammar doesn't contain any lexer rule definitions
but inline literal constants only, then the symbolicName list of
the parser is empty. The patch prepares the parser of Grammarinator
for such cases.
  • Loading branch information
renatahodovan committed May 20, 2024
1 parent a43ab46 commit 9eebab5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grammarinator/tool/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2023 Renata Hodovan, Akos Kiss.
# Copyright (c) 2018-2024 Renata Hodovan, Akos Kiss.
#
# Licensed under the BSD 3-Clause License
# <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
Expand Down Expand Up @@ -168,7 +168,7 @@ def _antlr_to_grammarinator_tree(self, antlr_node, parser, visited=None):
depth = max(depth, child_depth + 1)
else:
assert isinstance(antlr_node, TerminalNode), f'An ANTLR node must either be a ParserRuleContext or a TerminalNode but {antlr_node.__class__.__name__} was found.'
name, text = (parser.symbolicNames[antlr_node.symbol.type], antlr_node.symbol.text)
name, text = parser.symbolicNames[antlr_node.symbol.type] if len(parser.symbolicNames) >= antlr_node.symbol.type else '<INVALID>', antlr_node.symbol.text
assert name, f'{name} is None or empty'

if not self._hidden:
Expand Down

0 comments on commit 9eebab5

Please sign in to comment.