regexp: slightly more complicated tokenization to handle another case.

R/ [^/]/
R/ (/|abc)/
windows-drag
John Benediktsson 2019-03-17 13:12:41 -07:00
parent d59292faf6
commit 9f0bce7622
1 changed files with 20 additions and 4 deletions

View File

@ -197,11 +197,27 @@ PRIVATE>
<PRIVATE
: take-until ( lexer -- string )
dup skip-blank [
:: (take-until) ( col line end -- col' line )
"\\" end suffix :> tokens
col line [
[ [ tokens member? ] find-from ] keep swap [
CHAR: \ = [ [ 2 + ] dip t ] [ [ 1 + ] dip f ] if
] [
"Unterminated regexp" throw
] if*
] loop ;
:: take-until ( lexer -- string )
lexer skip-blank
lexer [
dupd [
[ [ "\\/" member? ] find-from ] keep swap [
CHAR: \ = [ [ 2 + ] dip t ] [ f ] if
[ [ "[(\\/" member? ] find-from ] keep swap [
{
{ CHAR: [ [ CHAR: ] (take-until) t ] }
{ CHAR: ( [ CHAR: ) (take-until) t ] }
{ CHAR: \ [ [ 2 + ] dip t ] }
{ CHAR: / [ f ] }
} case
] [
"Unterminated regexp" throw
] if*