首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在textX中解析Windows文件路径?

如何在textX中解析Windows文件路径?
EN

Stack Overflow用户
提问于 2021-12-07 11:34:41
回答 1查看 71关注 0票数 1

我需要解析Windows中的文件路径,确保我提供了一个csv文件。我已经在一个在线regex生成器中测试了regex,并确保它与我提供的文本相匹配。

Program.tx:

代码语言:javascript
复制
Program:
    'begin'
        commands*=Command
    'end'
;

Command:
     Test | Configuration
;

Test:
    'test'
;

Configuration:
    'configuration' location=/[a-zA-Z:a-zA-Z\\]+(\.csv$)/
;

test.dsl:

代码语言:javascript
复制
begin
    configuration C:\Users\me\Desktop\test.csv
end

program.py:

代码语言:javascript
复制
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(),我就无法解析提供的文件路径

代码语言:javascript
复制
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'.
EN

回答 1

Stack Overflow用户

发布于 2021-12-08 11:01:23

花了一天时间在这个问题上,结果发现textX不喜欢主播角色'$‘。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70259411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档