Search code examples
rubyparslet

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?


Solution

  • 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