Skip to content

Commit 1ded048

Browse files
authored
Merge pull request #1198 from lark-parser/issue1173
Fix for issue #1173
2 parents b07d6ff + adad165 commit 1ded048

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lark/load_grammar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,8 @@ def _make_rule_tuple(modifiers_tree, name, params, priority_tree, expansions):
10501050
if modifiers_tree.children:
10511051
m ,= modifiers_tree.children
10521052
expand1 = '?' in m
1053+
if expand1 and name.startswith('_'):
1054+
raise GrammarError("Inlined rules (_rule) cannot use the ?rule modifier.")
10531055
keep_all_tokens = '!' in m
10541056
else:
10551057
keep_all_tokens = False

tests/test_grammar.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ def test_list_grammar_imports(self):
281281
imports = list_grammar_imports('%import common.WS', [])
282282
assert len(imports) == 1 and imports[0].pkg_name == 'lark'
283283

284+
def test_inline_with_expand_single(self):
285+
grammar = r"""
286+
start: _a
287+
!?_a: "A"
288+
"""
289+
self.assertRaises(GrammarError, Lark, grammar)
290+
291+
284292
def test_line_breaks(self):
285293
p = Lark(r"""start: "a" \
286294
"b"

0 commit comments

Comments
 (0)