Browse Source

Switch to codecs.open for nearley tool

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Kaspar Emanuel 7 years ago
parent
commit
809ac8c9ea
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      lark/tools/nearley.py

+ 3
- 2
lark/tools/nearley.py View File

@@ -2,6 +2,7 @@


import os.path import os.path
import sys import sys
import codecs




from lark import Lark, InlineTransformer, Transformer from lark import Lark, InlineTransformer, Transformer
@@ -113,7 +114,7 @@ def _nearley_to_lark(g, builtin_path, n2l, js_code, folder_path, includes):
path = os.path.join(folder, arg[1:-1]) path = os.path.join(folder, arg[1:-1])
if path not in includes: if path not in includes:
includes.add(path) includes.add(path)
with open(path) as f:
with codecs.open(path, encoding='utf8') as f:
text = f.read() text = f.read()
rule_defs += _nearley_to_lark(text, builtin_path, n2l, js_code, os.path.abspath(os.path.dirname(path)), includes) rule_defs += _nearley_to_lark(text, builtin_path, n2l, js_code, os.path.abspath(os.path.dirname(path)), includes)
else: else:
@@ -175,7 +176,7 @@ def main():
return return


fn, start, nearley_lib = sys.argv[1:] fn, start, nearley_lib = sys.argv[1:]
with open(fn) as f:
with codecs.open(fn, encoding='utf8') as f:
grammar = f.read() grammar = f.read()
print(create_code_for_nearley_grammar(grammar, start, os.path.join(nearley_lib, 'builtin'), os.path.abspath(os.path.dirname(fn)))) print(create_code_for_nearley_grammar(grammar, start, os.path.join(nearley_lib, 'builtin'), os.path.abspath(os.path.dirname(fn))))




Loading…
Cancel
Save