1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser-combinators parser-combinators.regexp lists sequences kernel
4 promises strings unicode.case ;
10 [ ",*?" member? not ] satisfy ;
12 : 'string' ( -- parser )
13 'char' <+> [ >lower token ] <@ ;
15 : 'escaped-char' ( -- parser )
16 "\\" token any-char-parser &> [ 1token ] <@ ;
18 : 'escaped-string' ( -- parser )
19 'string' 'escaped-char' <|> ;
23 : 'glob' ( -- parser )
24 'term' <*> [ <and-parser> ] <@ ;
26 : 'union' ( -- parser )
27 'glob' "," token nonempty-list-of "{" "}" surrounded-by
30 LAZY: 'term' ( -- parser )
33 "?" token [ drop any-char-parser ] <@ <|>
34 "*" token [ drop any-char-parser <*> ] <@ <|>
35 'escaped-string' <|> ;
39 : <glob> ( string -- glob ) 'glob' just parse-1 just ;
41 : glob-matches? ( input glob -- ? )
42 [ >lower ] [ <glob> ] bi* parse nil? not ;