mirror of https://github.com/lark-parser/lark.git
Allow renaming relative import rule
%import .local.foo -> bar
This commit is contained in:
parent
9b22d41e49
commit
2f6b97cfd3
|
@ -139,7 +139,7 @@ RULES = {
|
|||
'declare': ['_DECLARE _declare_args _NL'],
|
||||
'import': ['_IMPORT _import_path _NL',
|
||||
'_IMPORT _import_path _LPAR name_list _RPAR _NL',
|
||||
'_IMPORT _import_path _TO TERMINAL _NL'],
|
||||
'_IMPORT _import_path _TO name _NL'],
|
||||
|
||||
'_import_path': ['import_lib', 'import_rel'],
|
||||
'import_lib': ['_import_args'],
|
||||
|
|
|
@ -1056,6 +1056,31 @@ def _make_parser_test(LEXER, PARSER):
|
|||
'y'])
|
||||
|
||||
|
||||
def test_relative_rule_import_subrule_no_conflict(self):
|
||||
l = _Lark_open(
|
||||
'test_relative_rule_import_subrule_no_conflict.lark',
|
||||
rel_to=__file__)
|
||||
x = l.parse('xaby')
|
||||
self.assertEqual(x.children, [Tree('expr', [
|
||||
'x',
|
||||
Tree('startab', [
|
||||
Tree('grammars__ab__expr', ['a', 'b']),
|
||||
]),
|
||||
'y'])])
|
||||
self.assertRaises((ParseError, UnexpectedInput),
|
||||
l.parse, 'xaxabyby')
|
||||
|
||||
|
||||
def test_relative_rule_import_rename(self):
|
||||
l = _Lark_open('test_relative_rule_import_rename.lark',
|
||||
rel_to=__file__)
|
||||
x = l.parse('xaabby')
|
||||
self.assertEqual(x.children, [
|
||||
'x',
|
||||
Tree('ab', ['a', Tree('ab', ['a', 'b']), 'b']),
|
||||
'y'])
|
||||
|
||||
|
||||
def test_multi_import(self):
|
||||
grammar = """
|
||||
start: NUMBER WORD
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
start: X ab Y
|
||||
|
||||
X: "x"
|
||||
Y: "y"
|
||||
|
||||
%import .grammars.ab.expr -> ab
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
start: expr
|
||||
|
||||
expr: X startab Y
|
||||
|
||||
X: "x"
|
||||
Y: "y"
|
||||
|
||||
%import .grammars.ab.startab
|
||||
|
Loading…
Reference in New Issue