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

Fix for issue #1173 #1198

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ def _make_rule_tuple(modifiers_tree, name, params, priority_tree, expansions):
if modifiers_tree.children:
m ,= modifiers_tree.children
expand1 = '?' in m
if expand1 and name.startswith('_'):
raise GrammarError("Inlined rules (_rule) cannot use the ?rule modifier.")
keep_all_tokens = '!' in m
else:
keep_all_tokens = False
Expand Down
8 changes: 8 additions & 0 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ def test_list_grammar_imports(self):
imports = list_grammar_imports('%import common.WS', [])
assert len(imports) == 1 and imports[0].pkg_name == 'lark'

def test_inline_with_expand_single(self):
grammar = r"""
start: _a
!?_a: "A"
"""
self.assertRaises(GrammarError, Lark, grammar)


def test_line_breaks(self):
p = Lark(r"""start: "a" \
"b"
Expand Down