1 Regular expressions can be used for string matching. Regular expressions
2 are written using / as quotes. For example,
5 /if/: { return token_if; }
6 | /then/: { return token_then; }
7 | /else/: { return token_else; }
8 | /while/: { return token_while; }
9 | /do/: { return token_do; }
10 | /for/: { return token_for; }
11 | /[a-zA-Z_][a-zA-Z_0-9]*/: { return token_id; }
12 | /[0-9]+/: { return token_integer; }
13 | _: { return token_error; }
16 The set of available meta characters is similar to what's available
17 in many tools such as lex or egrep.
20 e+ non-empty Kleene star
23 [a-z] character class (matches any one from 'a' to 'z')
24 [^a-z] negated character class (matches any one not from 'a' to 'z')
27 \xff hex code of character
28 \c the character c (even if it is a meta character)
30 Strings quoted with " may be mixed with regular expressions in the same
31 match statement. Notice that meta characters other than \ are not available
32 in " quoted strings. The match statement above may be implemented
36 "if": { return token_if; }
37 | "then": { return token_then; }
38 | "else": { return token_else; }
39 | "while": { return token_while; }
40 | "do": { return token_do; }
41 | "for": { return token_for; }
42 | /[a-zA-Z_][a-zA-Z_0-9]*/: { return token_id; }
43 | /[0-9]+/: { return token_integer; }
44 | _: { return token_error; }
47 Regular expression string matching is implemented using the usual
48 regexp -> nfa -> dfa -> compressed table algorithms. This feature
49 currently does not work with the matchall variant of match.