[Haskell-cafe] Need some help with Alex macros

Niklas Broberg niklas.broberg at gmail.com
Sun Oct 4 12:53:12 EDT 2009


Hi all,

I'm going crazy trying to get Alex to do what I want. I have the
following regexp macros:

@octEscape = [0123]? $octdig{1,2}
@hexEscape = 'u' $hexdig{4}
@charEscape = '\\' (@octEscape | @hexEscape | b | t | n | f | r | \" | \')

and the following rules:

    \' (. # [\'\\] | @charEscape) \'         { \p s -> CharTok (readCharTok s) }

    \" (. # [\"\\] | @charEscape)* \"        { \p s -> StringTok
(readStringTok s) }

I've tried a lot of variations on where to put the backslashes and
quotes to get it to do what I want, what you see above is just one
variation, but no matter what I try I can't get it to work.

> alexScanTokens $ show '\n'
*** Exception: lexical error

Can anyone help shed some light on this for me? Why can't I get alex
to recognize escapes inside character literals?

Cheers,

/Niklas


More information about the Haskell-Cafe mailing list