@@ -106,6 +106,45 @@ func swapCase*(r: Rune): Rune =
106106 return
107107 result = r.toUpper ()
108108
109+ func matchAsciiSet (n: Node , r: Rune ): bool =
110+ assert n.shorthands.len == 0
111+ result = r in n.cps or
112+ r in n.ranges
113+ result = (result and n.kind == reInSet) or
114+ (not result and n.kind == reNotSet)
115+
116+ func matchShorthand (n: Node , r: Rune ): bool =
117+ case n.kind
118+ of reWord: r.isWord ()
119+ of reNotAlphaNum: not r.isWord ()
120+ of reDigit: r.isDecimal ()
121+ of reNotDigit: not r.isDecimal ()
122+ of reWhiteSpace: r.isWhiteSpace ()
123+ of reNotWhiteSpace: not r.isWhiteSpace ()
124+ of reUCC: r.unicodeCategory () in n.cc
125+ of reNotUCC: r.unicodeCategory () notin n.cc
126+ of reWordAscii: r.isWordAscii ()
127+ of reNotAlphaNumAscii: not r.isWordAscii ()
128+ of reDigitAscii: r.isDigitAscii ()
129+ of reNotDigitAscii: not r.isDigitAscii ()
130+ of reWhiteSpaceAscii: r.isWhiteSpaceAscii ()
131+ of reNotWhiteSpaceAscii: not r.isWhiteSpaceAscii ()
132+ of reInSet, reNotSet: matchAsciiSet (n, r)
133+ else :
134+ doAssert false
135+ false
136+
137+ func matchSet (n: Node , r: Rune ): bool =
138+ result = r in n.cps or
139+ r in n.ranges
140+ if not result :
141+ for nn in n.shorthands:
142+ result = matchShorthand (nn, r)
143+ if result :
144+ break
145+ result = (result and n.kind == reInSet) or
146+ (not result and n.kind == reNotSet)
147+
109148func match * (n: Node , r: Rune ): bool {.inline .} =
110149 # # match for ``Node`` of matchable kind.
111150 # # Return whether the node matches
@@ -115,52 +154,25 @@ func match*(n: Node, r: Rune): bool {.inline.} =
115154 if n.kind == reChar:
116155 return n.cp == r
117156 case n.kind
118- of reEOE:
119- r == invalidRune
120- of reWord:
121- r.isWord ()
122- of reNotAlphaNum:
123- not r.isWord ()
124- of reDigit:
125- r.isDecimal ()
126- of reNotDigit:
127- not r.isDecimal ()
128- of reWhiteSpace:
129- r.isWhiteSpace ()
130- of reNotWhiteSpace:
131- not r.isWhiteSpace ()
132- of reInSet, reNotSet:
133- var matches = (
134- r in n.cps or
135- r in n.ranges)
136- if not matches:
137- for nn in n.shorthands:
138- matches = nn.match (r)
139- if matches: break
140- ((matches and n.kind == reInSet) or
141- (not matches and n.kind == reNotSet))
142- of reAny:
143- r != lineBreakRune
144- of reAnyNL:
145- true
146- of reCharCI:
147- r == n.cp or r == n.cp.swapCase ()
148- of reWordAscii:
149- r.isWordAscii ()
150- of reDigitAscii:
151- r.isDigitAscii ()
152- of reWhiteSpaceAscii:
153- r.isWhiteSpaceAscii ()
154- of reUCC:
155- r.unicodeCategory () in n.cc
156- of reNotAlphaNumAscii:
157- not r.isWordAscii ()
158- of reNotDigitAscii:
159- not r.isDigitAscii ()
160- of reNotWhiteSpaceAscii:
161- not r.isWhiteSpaceAscii ()
162- of reNotUCC:
163- r.unicodeCategory () notin n.cc
157+ of reEOE: r == invalidRune
158+ of reWord: r.isWord ()
159+ of reNotAlphaNum: not r.isWord ()
160+ of reDigit: r.isDecimal ()
161+ of reNotDigit: not r.isDecimal ()
162+ of reWhiteSpace: r.isWhiteSpace ()
163+ of reNotWhiteSpace: not r.isWhiteSpace ()
164+ of reAny: r != lineBreakRune
165+ of reAnyNL: true
166+ of reCharCI: r == n.cp or r == n.cp.swapCase ()
167+ of reUCC: r.unicodeCategory () in n.cc
168+ of reNotUCC: r.unicodeCategory () notin n.cc
169+ of reWordAscii: r.isWordAscii ()
170+ of reNotAlphaNumAscii: not r.isWordAscii ()
171+ of reDigitAscii: r.isDigitAscii ()
172+ of reNotDigitAscii: not r.isDigitAscii ()
173+ of reWhiteSpaceAscii: r.isWhiteSpaceAscii ()
174+ of reNotWhiteSpaceAscii: not r.isWhiteSpaceAscii ()
175+ of reInSet, reNotSet: matchSet (n, r)
164176 else :
165177 assert n.kind == reChar
166178 n.cp == r
0 commit comments