mirror of https://github.com/lark-parser/lark.git
Refactor nearley builtin and include
This commit is contained in:
parent
3ea0b35c9f
commit
4539152b32
|
@ -111,17 +111,9 @@ def _nearley_to_lark(g, builtin_path, n2l, js_code, folder_path, includes=None):
|
||||||
for statement in tree.children:
|
for statement in tree.children:
|
||||||
if statement.data == 'directive':
|
if statement.data == 'directive':
|
||||||
directive, arg = statement.children
|
directive, arg = statement.children
|
||||||
if directive == 'builtin':
|
if directive == 'builtin' or directive == 'include':
|
||||||
path = os.path.join(builtin_path, arg[1:-1])
|
folder = builtin_path if directive == 'builtin' else folder_path
|
||||||
if path not in includes:
|
path = os.path.join(folder, arg[1:-1])
|
||||||
includes.append(path)
|
|
||||||
with open(path) as f:
|
|
||||||
text = f.read()
|
|
||||||
[included_rule_defs, included_includes] = _nearley_to_lark(text, builtin_path, n2l, js_code, os.path.abspath(os.path.dirname(path)), includes)
|
|
||||||
rule_defs += included_rule_defs
|
|
||||||
includes += included_includes
|
|
||||||
elif directive == 'include':
|
|
||||||
path = os.path.join(folder_path, arg[1:-1])
|
|
||||||
if path not in includes:
|
if path not in includes:
|
||||||
includes.append(path)
|
includes.append(path)
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
|
|
Loading…
Reference in New Issue