1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math math.order words regexp.utils
4 unicode.categories combinators.short-circuit ;
7 SINGLETONS: any-char any-char-no-nl
8 letter-class LETTER-class Letter-class digit-class
9 alpha-class non-newline-blank-class
10 ascii-class punctuation-class java-printable-class blank-class
11 control-character-class hex-digit-class java-blank-class c-identifier-class
12 unmatchable-class terminator-class word-boundary-class ;
14 SINGLETONS: beginning-of-input beginning-of-line
15 end-of-input end-of-line ;
18 TUPLE: character-class-range from to ; INSTANCE: character-class-range node
20 GENERIC: class-member? ( obj class -- ? )
22 M: t class-member? ( obj class -- ? ) 2drop f ;
24 M: integer class-member? ( obj class -- ? ) 2drop f ;
26 M: character-class-range class-member? ( obj class -- ? )
27 [ from>> ] [ to>> ] bi between? ;
29 M: any-char class-member? ( obj class -- ? )
32 M: any-char-no-nl class-member? ( obj class -- ? )
35 M: letter-class class-member? ( obj class -- ? )
38 M: LETTER-class class-member? ( obj class -- ? )
41 M: Letter-class class-member? ( obj class -- ? )
44 M: ascii-class class-member? ( obj class -- ? )
47 M: digit-class class-member? ( obj class -- ? )
50 M: c-identifier-class class-member? ( obj class -- ? )
52 { [ digit? ] [ Letter? ] [ CHAR: _ = ] } 1|| ;
54 M: alpha-class class-member? ( obj class -- ? )
57 M: punctuation-class class-member? ( obj class -- ? )
60 M: java-printable-class class-member? ( obj class -- ? )
61 drop java-printable? ;
63 M: non-newline-blank-class class-member? ( obj class -- ? )
64 drop { [ blank? ] [ CHAR: \n = not ] } 1&& ;
66 M: control-character-class class-member? ( obj class -- ? )
69 M: hex-digit-class class-member? ( obj class -- ? )
72 M: java-blank-class class-member? ( obj class -- ? )
75 M: unmatchable-class class-member? ( obj class -- ? )
78 M: terminator-class class-member? ( obj class -- ? )
87 M: beginning-of-line class-member? ( obj class -- ? )
90 M: end-of-line class-member? ( obj class -- ? )