gcc config
[prop.git] / notes / Regexp.txt
blob6e6090d16bb895621a8b4bf63e473807c3b1dcaf
1 Regular expressions can be used for string matching.   Regular expressions
2 are written using / as quotes.   For example,
4     match (token) {
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; }
14     }
16 The set of available meta characters is similar to what's available
17 in many tools such as lex or egrep.
19     e*         Kleene star
20     e+         non-empty Kleene star
21     (e)        parenthesis
22     e1|e2      disjunction
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')
25     \n         newline
26     \t         tab
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
33 alternatively as:
35     match (token) {
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; }
45     }
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.