How to parse a Windows file path in textX?

123 Views Asked by At

I need to parse through a file path in Windows, make sure I have provided a csv file. I have tested the regex in an online regex generator and made sure it matches the text I provide it.

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
end

program.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)

Once I use Robot.interpret(), I cannot parse through the provided filepath

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'.
1

There are 1 best solutions below

0
On

After spending a day on the problem, turns out textX doesn't like the anchor character - '$'.