haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
297 stars 82 forks source link

tiger.x example string parser bug #180

Closed 21it closed 1 year ago

21it commented 3 years ago

Here last argument of Lexeme constructor is always Just "\"", but I guess it's supposed to be raw full representation of parsed string

https://github.com/simonmar/alex/blob/a2a10a1a58a2a5066e69ecff205a27d5a1ed66c0/examples/tiger.x#L254

andreasabel commented 3 years ago

This bug report is a bit terse. Could you flesh it out with the usual

andreasabel commented 1 year ago

Ok, after getting tiger.x compiled, I see the following output:

$ cat tiger/Literals.txt 
123 "Hello, world!"

$ ./tiger.bin tiger/Literals.txt 
Beginning analysis of the Tiger program in file tiger/Literals.txt
[  Lexeme class=INT 123 posn=1:1 string="123",  Lexeme class=STRING "Hello, world!" posn=1:19 string="\"",  Lexeme EOF]

So, both posn and string are wrong: string contains just the last character of the parsed input, and posn points at the closing " rather than at the opening one.

andreasabel commented 1 year ago

PR #226 fixes the wrong posn and removes the wrong string component in Lexeme class=STRING.