Allow renaming relative import rule

%import .local.foo -> bar
This commit is contained in:
Rogdham 2019-02-20 11:52:04 +01:00
parent 9b22d41e49
commit 2f6b97cfd3
4 changed files with 42 additions and 1 deletions

View File

@ -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'],

View File

@ -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

View File

@ -0,0 +1,7 @@
start: X ab Y
X: "x"
Y: "y"
%import .grammars.ab.expr -> ab

View File

@ -0,0 +1,9 @@
start: expr
expr: X startab Y
X: "x"
Y: "y"
%import .grammars.ab.startab