Skip to content

Commit

Permalink
Merge pull request #1198 from lark-parser/issue1173
Browse files Browse the repository at this point in the history
Fix for issue #1173
  • Loading branch information
erezsh authored Oct 7, 2022
2 parents b07d6ff + adad165 commit 1ded048
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 1ded048

Please sign in to comment.