您将如何实现可以导入文件并仍然使用LARK对其进行语法分析的语法?
f.e .:
@import file.txt
.....
最佳答案
我发现了一个与您正在寻找的GitHub相关的GitHub?
https://github.com/lark-parser/lark
from lark import Lark
with open('file_to_read.txt', 'r') as file:
data = file.read().replace('\n', '') #assumes you want to remove \n
l = Lark('''start: WORD "," WORD "!"
%import common.WORD // imports from terminal library
%ignore " " // Disregard spaces in text
''')
print( l.parse("Hello, World!") )
print( l.parse(data) )
如果要打开文件并将其用作百灵鸟
from lark import Lark
with open('file_to_read.txt', 'r') as file:
data = file.read().replace('\n', '') #assumes you want to remove \n
l = Lark(data)
print( l.parse("Hello, World!") )
print( l.parse("your string to parse") )
关于python - LARK:解析:实现导入文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58783994/