From 7724ad2387e355888e6607ede810c0776a37a573 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 13 Sep 2008 18:20:38 -0500 Subject: [PATCH] allow |b b| || regexps --- unfinished/regexp2/parser/parser-tests.factor | 4 ++++ unfinished/regexp2/parser/parser.factor | 2 +- unfinished/regexp2/regexp2-tests.factor | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/unfinished/regexp2/parser/parser-tests.factor b/unfinished/regexp2/parser/parser-tests.factor index 9dc7dc7909..6911e8e76d 100644 --- a/unfinished/regexp2/parser/parser-tests.factor +++ b/unfinished/regexp2/parser/parser-tests.factor @@ -31,3 +31,7 @@ IN: regexp2.parser [ ] [ "[a-c]" test-regexp ] unit-test [ ] [ "[^a-c]" test-regexp ] unit-test [ "[^]" test-regexp ] must-fail + +[ ] [ "|b" test-regexp ] unit-test +[ ] [ "b|" test-regexp ] unit-test +[ ] [ "||" test-regexp ] unit-test diff --git a/unfinished/regexp2/parser/parser.factor b/unfinished/regexp2/parser/parser.factor index a970f82aab..fb1bd08bfe 100644 --- a/unfinished/regexp2/parser/parser.factor +++ b/unfinished/regexp2/parser/parser.factor @@ -67,7 +67,7 @@ left-parenthesis pipe caret dash ; : ( obj -- negation ) negation boa ; : ( seq -- concatenation ) >vector get-reversed-regexp [ reverse ] when - concatenation boa ; + [ epsilon ] [ concatenation boa ] if-empty ; : ( seq -- alternation ) >vector alternation boa ; : ( obj -- capture-group ) capture-group boa ; : ( obj -- kleene-star ) kleene-star boa ; diff --git a/unfinished/regexp2/regexp2-tests.factor b/unfinished/regexp2/regexp2-tests.factor index f691c2becf..e77a7a4419 100644 --- a/unfinished/regexp2/regexp2-tests.factor +++ b/unfinished/regexp2/regexp2-tests.factor @@ -14,6 +14,13 @@ IN: regexp2-tests [ t ] [ "c" "a|b|c" matches? ] unit-test [ f ] [ "c" "d|e|f" matches? ] unit-test +[ t ] [ "b" "|b" matches? ] unit-test +[ t ] [ "b" "b|" matches? ] unit-test +[ t ] [ "" "b|" matches? ] unit-test +[ t ] [ "" "b|" matches? ] unit-test +[ f ] [ "" "|" matches? ] unit-test +[ f ] [ "" "|||||||" matches? ] unit-test + [ f ] [ "aa" "a|b|c" matches? ] unit-test [ f ] [ "bb" "a|b|c" matches? ] unit-test [ f ] [ "cc" "a|b|c" matches? ] unit-test