Closed aleclofabbro closed 3 years ago
You have to be careful when writing Ohm grammars inside of a JavaScript string literal. The \n
here is an escape sequence that is replaced with a literal newline character before Ohm sees the string.
It's especially since Ohm supports many of the same escape sequences as JavaScript, so you have to be mindful of which level is interpreting your escape!
There are two solutions:
String.raw
:
const grString = String.raw`
lineTerminator = "\n"
...
`
const grString = `
lineTerminator = "\\n"
`
when defining grammar that uses escaped characters as a js string e.g.:
with
Although it works as expected when :
note that
lineTerminator
is taken from ohm's javascript grammar example