我需要解析Windows中的文件路径,确保我提供了一个csv文件。我已经在一个在线regex生成器中测试了regex,并确保它与我提供的文本相匹配。
Program.tx:
Program:
'begin'
commands*=Command
'end'
;
Command:
Test | Configuration
;
Test:
'test'
;
Configuration:
'configuration' location=/[a-zA-Z:a-zA-Z\\]+(\.csv$)/
;test.dsl:
begin
configuration C:\Users\me\Desktop\test.csv
endprogram.py:
from textx import metamodel_from_file
from Input import Input
class Robot(object):
def __init__(self):
self.input_location = None
def setInput(self, location):
self.input = Input(location)
def interpret(self, model):
for c in model.commands:
if c.__class__.__name__ == "Configuration":
self.setInput(c.location)
robot_mm = metamodel_from_file('Program.tx')
robot_model = robot_mm.model_from_file('test.dsl')
robot = Robot()
robot.interpret(robot_model)一旦我使用了Robot.interpret(),我就无法解析提供的文件路径
textx.exceptions.TextXSyntaxError: None:2:19: error: Expected '[a-zA-Z:a-zA-Z\\]+(\.csv$)' at position c:\Users\me\Desktop\test.dsl:(2, 19) => 'on *C:\Users\me\Des'.发布于 2021-12-08 11:01:23
花了一天时间在这个问题上,结果发现textX不喜欢主播角色'$‘。
https://stackoverflow.com/questions/70259411
复制相似问题