Simmo
Simmo

Reputation: 1729

How do I get Parslet to tell the the char that failed?

I've got the following in Parslet.

'] at line 1 char 27.
|        |- Expected "\n", but got "\\" at line 1 char 27.
|        `- Expected "\r\n", but got "\\n" at line 1 char 27.

which I'm slightly confused about as there isn't two slashed in the original string. To help me debug, is there a way of outputting the particular char and preferably the ordinal number too? Or do I have to refer back to the original string?

Upvotes: 1

Views: 60

Answers (1)

Nigel Thorne
Nigel Thorne

Reputation: 21548

It looks like you are trying to handle line end being "\n" or "\r\n" but your input string literally have a '\' and a literal 'n' which means the escaping in your input string isn't right.

It's probably a use of ' instead of "

eg.

irb(main):001:0> "\\n".length
=> 2
irb(main):002:0> "\n".length
=> 1
irb(main):003:0> '\n'.length
=> 2

Upvotes: 1

Related Questions