Bläddra i källkod

Support relative rule import in interactive environment (Issue #335)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.0
Erez Shinan 5 år sedan
förälder
incheckning
4e6f92b03b
1 ändrade filer med 8 tillägg och 2 borttagningar
  1. +8
    -2
      lark/load_grammar.py

+ 8
- 2
lark/load_grammar.py Visa fil

@@ -749,10 +749,16 @@ class GrammarLoader:
g = import_grammar(grammar_path)
else: # Relative import
if grammar_name == '<string>': # Import relative to script file path if grammar is coded in script
base_file = os.path.abspath(sys.modules['__main__'].__file__)
try:
base_file = os.path.abspath(sys.modules['__main__'].__file__)
except AttributeError:
base_file = None
else:
base_file = grammar_name # Import relative to grammar file path if external grammar file
base_path = os.path.split(base_file)[0]
if base_file:
base_path = os.path.split(base_file)[0]
else:
base_path = os.path.abspath(os.path.curdir)
g = import_grammar(grammar_path, base_paths=[base_path])

aliases_dict = dict(zip(names, aliases))


Laddar…
Avbryt
Spara