Closed andykais closed 4 years ago
Hmm, it seems to work for me?
$ nearley-test <(pbpaste | nearleyc) -i "'\n'" -q
[
[
[ "'", [ [ '\\', 'n' ] ], "'" ]
]
]
If you're typing directly into nearley-test (as opposed to using -i) I wonder if hitting "enter" is creating a second newline at the end of your input, which is what is causing the problem.
hmm Ill see if I can create a repro tonight, thanks for responding!
ah. Looks like my problem is that javascript string literals (`) interpret newline characters as newlines directly. So the following strings are equivilant:
a = `\n`
b = `
`
a === b
// true
If I create a parser like so:
then both of these inputs are invalid with the error
Unexpected "\n".
:I would prefer that the latter is invalid but the former is valid (much how writing the former would be valid in say javascript, but the latter would not be. What I actually have to end up doing is writing
when I want to express a newline within quotes. Is there a way to make nearley parse strings closer to how most languages do?