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

Initial support for import * (WIP) #1446

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
10 changes: 7 additions & 3 deletions lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
'_import_path': ['import_lib', 'import_rel'],
'import_lib': ['_import_args'],
'import_rel': ['_DOT _import_args'],
'_import_args': ['name', '_import_args _DOT name'],
'_import_args': ['name', '_import_args _DOT name', '_import_args _DOT OP'],

'name_list': ['_name_list'],
'_name_list': ['name', '_name_list _COMMA name'],
Expand Down Expand Up @@ -1325,8 +1325,12 @@ def do_import(self, dotted_path: Tuple[str, ...], base_path: Optional[str], alia
self.used_files[joined_path] = h

gb = GrammarBuilder(self.global_keep_all_tokens, self.import_paths, self.used_files)
gb.load_grammar(text, joined_path, mangle)
gb._remove_unused(map(mangle, aliases))
if '*' in aliases:
assert len(aliases) == 1
gb.load_grammar(text, joined_path, base_mangle)
else:
gb.load_grammar(text, joined_path, mangle)
gb._remove_unused(map(mangle, aliases))
for name in gb._definitions:
if name in self._definitions:
raise GrammarError("Cannot import '%s' from '%s': Symbol already defined." % (name, grammar_path))
Expand Down
Loading