From 18fa11c511ba1b600b43b7196d72f732e4f3ccf5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 6 Jan 2010 15:34:36 -0800 Subject: Some fine tuning in regex grammar. --- ChangeLog | 12 ++++++++++++ parser.y | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f71577ca..56ae1379 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-01-06 Kaz Kylheku + + Some fine tuning in regex grammar. + + * parser.y (regex): Empty regex handled by + allowing regex to generate empty, rather than + a special case production for '/' '/'. Thus + empty subexpressions are possible. + (regbranch, regterm): Complement is handled + in regbranch, so that it has lower precedence + than aggregation. + 2010-01-05 Kaz Kylheku Implemented the regular expression ~ and & operators. diff --git a/parser.y b/parser.y index 51386217..cc0815c8 100644 --- a/parser.y +++ b/parser.y @@ -449,7 +449,6 @@ expr : IDENT { $$ = intern(string_own($1), nil); } ; regex : '/' regexpr '/' { $$ = $2; } - | '/' '/' { $$ = nil; } | '/' error { $$ = nil; yybadtoken(yychar, lit("regex")); } ; @@ -459,10 +458,12 @@ regexpr : regbranch { $$ = $1; } $3, nao), nao); } | regexpr '&' regexpr { $$ = list(list(and_s, $1, $3, nao), 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); } @@ -474,7 +475,6 @@ regterm : '[' regclass ']' { $$ = cons(set_s, $2); } | regterm '*' { $$ = list(zeroplus_s, $1, nao); } | regterm '+' { $$ = list(oneplus_s, $1, nao); } | regterm '?' { $$ = list(optional_s, $1, nao); } - | '~' regterm { $$ = list(compl_s, $2, nao); } | REGCHAR { $$ = chr($1); } | '(' regexpr ')' { $$ = cons(compound_s, $2); } | '(' error { $$ = nil; -- cgit v1.2.3