Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that label names in processor start with capital letter #231

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grammarinator/tool/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ def build_expr(node, parent_id):
nonlocal alt_idx
conditions = [find_conditions(child) for child in children]
labels = [str(child.identifier().TOKEN_REF() or child.identifier().RULE_REF()) for child in children if child.identifier()] if isinstance(node, ANTLRv4Parser.RuleAltListContext) else []
# Ensure to start labels with capital letter, since ANTLR will also create a context with capital start character.
# It's important to keep them in sync since grammarinator-parse will use this graph for comparison.
labels = [label[0].upper() + label[1:] for label in labels]
recurring_labels = {name for name, cnt in Counter(labels).items() if cnt > 1}
assert len(labels) == 0 or len(labels) == len(children)
alt_id = graph.add_node(AlternationNode(idx=alt_idx, conditions=append_unique(graph.alt_conds, conditions) if all(isfloat(cond) for cond in conditions) else conditions, rule_id=rule.id))
Expand Down
Loading