0

The #include pragma with relative path does not work. With a grammar file containing

...
#include :: "secondary.ebnf"

and code to compile it

with open("/full/path/to/main.ebnf") as source:
    psr = tatsu.compile(source.read())

I'm getting tatsu.exceptions.ParseError caused by No such file or directory '/short/path/secondary.ebnf'.

Absolute paths work, but relative paths do not - there was always at least one path component missing no matter what was the os.getcwd() when running the code.

volferine
  • 372
  • 1
  • 9

1 Answers1

0

The problem is that with this method of grammar compilation TatSu cannot know the path to the grammar file, yet it uses the filename settings when deriving path to the included grammar. So as to make this approach work, it is necessary that filename is provided to the compile call like

filename = "/full/path/to/main.ebnf"
with open(filename) as source:
    psr = tatsu.compile(source.read(), filename=filename)
volferine
  • 372
  • 1
  • 9