# HG changeset patch # User Mike Pavone # Date 1388970033 28800 # Node ID dae093baf36cc8d338f20698930cb869474ee139 # Parent c463a891ccd3d577b2c7095d61352d1ef316e47f Optimized implementation of character classes diff -r c463a891ccd3 -r dae093baf36c modules/parser.tp --- a/modules/parser.tp Fri Jan 03 22:13:34 2014 -0800 +++ b/modules/parser.tp Sun Jan 05 17:00:33 2014 -0800 @@ -174,29 +174,35 @@ eval: rawchars :chars { orig <- chars chars <- expandClass: chars - //TODO: Use a more sophisticated approach for large classes + charmap <- "" + char <- 0 + while: { char < 256 } do: { + mchar <- 0 + found <- false + while: { mchar < (chars byte_length)} do: { + if: (chars byte: mchar) = char { + found <- true + mchar <- chars byte_length + } + mchar <- mchar + 1 + } + charmap <- charmap . (if: found { "t" } else: { "f" }) + char <- char + 1 + } + t <- "t" byte: 0 quote: :tomatch { if: (tomatch isString?) { - check <- 0 - - nomatch <- true - while: { nomatch && check < (chars byte_length) } do: { - if: (tomatch byte: 0) = (chars byte: check) { - nomatch <- false - } - check <- check + 1 - } - if: nomatch { - #{ - matched? <- { false } - } - } else: { + if: (charmap byte: (tomatch byte: 0)) = t { #{ matched? <- { true } matchlen <- { 1 } basicYield? <- { true } yield <- { tomatch from: 0 withLength: 1 } } + } else: { + #{ + matched? <- { false } + } } } else: { #{