diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2010-01-13 12:24:00 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2010-01-13 12:24:00 -0800 |
commit | b839b5a212fdd77c5dc95b684d7e6790292bb3dc (patch) | |
tree | 12aa13021e6af8b1a276e6bc00f712b76ee1631a /parser.y | |
parent | c017faf62d69d43219f7d1d651f7a46083f8a6a4 (diff) | |
download | txr-b839b5a212fdd77c5dc95b684d7e6790292bb3dc.tar.gz txr-b839b5a212fdd77c5dc95b684d7e6790292bb3dc.tar.bz2 txr-b839b5a212fdd77c5dc95b684d7e6790292bb3dc.zip |
Impelement derivative-based regular expressions.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -453,17 +453,17 @@ regex : '/' regexpr '/' { $$ = $2; } yybadtoken(yychar, lit("regex")); } ; -regexpr : regbranch { $$ = $1; } - | regexpr '|' regexpr { $$ = list(list(or_s, $1, - $3, nao), nao); } - | regexpr '&' regexpr { $$ = list(list(and_s, $1, - $3, nao), nao); } +regexpr : regbranch { $$ = if3(cdr($1), + cons(compound_s, $1), + car($1)); } + | regexpr '|' regexpr { $$ = list(or_s, $1, $3, nao); } + | regexpr '&' regexpr { $$ = list(and_s, $1, $3, nao); } + | '~' regexpr { $$ = list(compl_s, $2, nao); } | /* empty */ { $$ = nil; } ; regbranch : regterm { $$ = cons($1, nil); } | regterm regbranch { $$ = cons($1, $2); } - | '~' regbranch { $$ = cons(cons(compl_s, $2), nil); } ; regterm : '[' regclass ']' { $$ = cons(set_s, $2); } @@ -476,7 +476,7 @@ regterm : '[' regclass ']' { $$ = cons(set_s, $2); } | regterm '+' { $$ = list(oneplus_s, $1, nao); } | regterm '?' { $$ = list(optional_s, $1, nao); } | REGCHAR { $$ = chr($1); } - | '(' regexpr ')' { $$ = cons(compound_s, $2); } + | '(' regexpr ')' { $$ = $2; } | '(' error { $$ = nil; yybadtoken(yychar, lit("regex subexpression")); } |