Lexer fails to detect escaped chars in strings #4

Closed
nougad opened this Issue Feb 12, 2013 · 1 comment

Projects

None yet

2 participants

@nougad
Contributor
nougad commented Feb 12, 2013

Program (lexlua):

main = Lua.Lexer.llex <$> getContents >>= print

call:

$ echo "print('\'s\'')" | lexlua
lua2lua: lexical error near line: 1 col: 11 at char s 
$ echo 'print("\"s\"")' | lexlua
lua2lua: lexical error near line: 1 col: 11 at char s

without quotes it works fine:

$ echo "print('s')" | lexlua
[(identifier: "print",Right (AlexPn 0 1 1)),(`(`,Right (AlexPn 5 1 6)),(string: "s",Right (AlexPn 6 1 7)),(`)`,Right (AlexPn 9 1 10)),(EOF,Left EOF)]
@osa1 osa1 added a commit that referenced this issue Feb 14, 2013
@osa1 undo commit baf891f (issue #4) d503553
@osa1
Owner
osa1 commented Feb 14, 2013

Thanks for reporting.

It's funny that string lexing was actually working before commit baf891f and I broke it with this "fix escape character syntax" commit.

I'm testing lexing against Lua manual's examples, I think it's working now:

➜  src git:(master) ✗ cat test.hs
import Language.Lua
import Control.Applicative ((<$>))

main = llex <$> getContents >>= print
➜  src git:(master) ✗ ghc --make -O2 test.hs
[9 of 9] Compiling Main             ( test.hs, test.o )
Linking test ...
➜  src git:(master) ✗ ./test
'alo\n123"'
"alo\n123\""
'\97lo\10\04923"'
[[alo
     123"]]
[==[
     alo
     123"]==]^D
[(string: "alo\\n123\"",Right (AlexPn 0 1 1)),(string: "alo\\n123\\\"",Right (AlexPn 12 2 1)),(string: "\\97lo\\10\\04923\"",Right (AlexPn 25 3 1)),(string: "alo\n     123\"",Right (AlexPn 43 4 1)),(string: "     alo\n     123\"",Right (AlexPn 61 6 1)),(EOF,Left EOF)]

your examples:

➜  src git:(master) ✗ ./test 
print("\"s\"")
print('\'s\'')^D
[(identifier: "print",Right (AlexPn 0 1 1)),(`(`,Right (AlexPn 5 1 6)),(string: "\\\"s\\\"",Right (AlexPn 6 1 7)),(`)`,Right (AlexPn 13 1 14)),(identifier: "print",Right (AlexPn 15 2 1)),(`(`,Right (AlexPn 20 2 6)),(string: "\\'s\\'",Right (AlexPn 21 2 7)),(`)`,Right (AlexPn 28 2 14)),(EOF,Left EOF)]
@osa1 osa1 closed this Feb 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment