[Haskell-cafe] Few Alex questions
Bernie Pope
florbitous at gmail.com
Fri May 1 03:16:39 EDT 2009
2009/5/1 Dimitry Golubovsky <golubovsky at gmail.com>
<snip>
Can beginning of line (caret) be recognized by Alex?
You can match the start of a line using a (left) context on a rule. See the
docs here:
http://www.haskell.org/alex/doc/html/alex-files.html#contexts
Where it says: "The left context matches the character which immediately
precedes the token in the input stream. The character immediately preceding
the beginning of the stream is assumed to be ‘\n’. The special left-context
‘^’ is shorthand for ‘\n^’."
Alex also supports right contexts too.
<snip>
Is this correct understanding that if we want to match any character
> except for an asterisk, then Alex would like to see [^\*] rather than
> [^*]? And [^\/] rather than [^/]?
>
> Or would it be better to use a hex code for the asterisk and slash?
In a character set you must escape certain special characters. The list of
special characters is specified in the docs here:
http://www.haskell.org/alex/doc/html/syntax.html#lexical
The key line is:
$special = [\.\;\,\$\|\*\+\?\#\~\-\{\}\(\)\[\]\^\/]
I'd try to avoid character codes where possible.
Cheers,
Bernie.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090501/317d2cb9/attachment.htm
More information about the Haskell-Cafe
mailing list