Add \Q...\E (escape all characters between \Q and \E)
parent
b629d6ebe1
commit
8fadc570fc
extra/regexp
|
@ -149,3 +149,8 @@ IN: regexp-tests
|
|||
[ f ] [ "abc" "[\\p{Upper}]{3}" matches? ] unit-test
|
||||
[ t ] [ "ABC" "[\\p{Upper}]{3}" matches? ] unit-test
|
||||
|
||||
[ t ] [ "" "\\Q\\E" matches? ] unit-test
|
||||
[ f ] [ "a" "\\Q\\E" matches? ] unit-test
|
||||
[ t ] [ "|*+" "\\Q|*+\\E" matches? ] unit-test
|
||||
[ f ] [ "abc" "\\Q|*+\\E" matches? ] unit-test
|
||||
|
||||
|
|
|
@ -109,11 +109,17 @@ IN: regexp
|
|||
{ "\\p{Space}" [ java-blank? ] }
|
||||
} [ first2 satisfy-token ] [ <|> ] map-reduce ;
|
||||
|
||||
: 'escaped-seq' ( -- parser )
|
||||
"\\Q" token
|
||||
any-char-parser <*> [ token ] <@ &>
|
||||
"\\E" token <& ;
|
||||
|
||||
: 'escape-seq' ( -- parser )
|
||||
'simple-escape-char'
|
||||
'predefined-char-class' <|>
|
||||
'octal' <|>
|
||||
'hex' <|>
|
||||
'escaped-seq' <|>
|
||||
'control-character' <|>
|
||||
'posix-character-class' <|> ;
|
||||
|
||||
|
@ -239,8 +245,3 @@ M: object >regexp ;
|
|||
: R" CHAR: " parse-regexp ; parsing
|
||||
: R' CHAR: ' parse-regexp ; parsing
|
||||
: R` CHAR: ` parse-regexp ; parsing
|
||||
|
||||
! \Q \E
|
||||
! Must escape to use as literals
|
||||
! : meta-chars "[\\^$.|?*+()" ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue