Mercurial > repos > tabletprog
comparison modules/parser.tp @ 237:dae093baf36c
Optimized implementation of character classes
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 05 Jan 2014 17:00:33 -0800 |
parents | c463a891ccd3 |
children | 6aab8a5a2be9 |
comparison
equal
deleted
inserted
replaced
236:c463a891ccd3 | 237:dae093baf36c |
---|---|
172 } | 172 } |
173 charClass <- macro: :rawchars { | 173 charClass <- macro: :rawchars { |
174 eval: rawchars :chars { | 174 eval: rawchars :chars { |
175 orig <- chars | 175 orig <- chars |
176 chars <- expandClass: chars | 176 chars <- expandClass: chars |
177 //TODO: Use a more sophisticated approach for large classes | 177 charmap <- "" |
178 char <- 0 | |
179 while: { char < 256 } do: { | |
180 mchar <- 0 | |
181 found <- false | |
182 while: { mchar < (chars byte_length)} do: { | |
183 if: (chars byte: mchar) = char { | |
184 found <- true | |
185 mchar <- chars byte_length | |
186 } | |
187 mchar <- mchar + 1 | |
188 } | |
189 charmap <- charmap . (if: found { "t" } else: { "f" }) | |
190 char <- char + 1 | |
191 } | |
192 t <- "t" byte: 0 | |
178 quote: :tomatch { | 193 quote: :tomatch { |
179 if: (tomatch isString?) { | 194 if: (tomatch isString?) { |
180 check <- 0 | 195 if: (charmap byte: (tomatch byte: 0)) = t { |
181 | |
182 nomatch <- true | |
183 while: { nomatch && check < (chars byte_length) } do: { | |
184 if: (tomatch byte: 0) = (chars byte: check) { | |
185 nomatch <- false | |
186 } | |
187 check <- check + 1 | |
188 } | |
189 if: nomatch { | |
190 #{ | |
191 matched? <- { false } | |
192 } | |
193 } else: { | |
194 #{ | 196 #{ |
195 matched? <- { true } | 197 matched? <- { true } |
196 matchlen <- { 1 } | 198 matchlen <- { 1 } |
197 basicYield? <- { true } | 199 basicYield? <- { true } |
198 yield <- { tomatch from: 0 withLength: 1 } | 200 yield <- { tomatch from: 0 withLength: 1 } |
201 } | |
202 } else: { | |
203 #{ | |
204 matched? <- { false } | |
199 } | 205 } |
200 } | 206 } |
201 } else: { | 207 } else: { |
202 #{ | 208 #{ |
203 matched? <- { false } | 209 matched? <- { false } |