]> gitweb.factorcode.org Git - factor.git/commitdiff
peg.parsers: make range-pattern more efficient for single characters.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 23 Nov 2020 21:27:21 +0000 (13:27 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 23 Nov 2020 21:35:13 +0000 (13:35 -0800)
basis/peg/parsers/parsers.factor

index ca4a8654c4592258c65ca7e685b331c9de5c8a92..9b575778b5611d66152740acac1b668820053aaa 100644 (file)
@@ -8,14 +8,12 @@ IN: peg.parsers
 
 TUPLE: just-parser p1 ;
 
-CONSTANT: just-pattern [
-    dup [
-        dup remaining>> empty? [ drop f ] unless
-    ] when
-]
-
 M: just-parser (compile)
-    p1>> compile-parser-quot just-pattern compose ;
+    p1>> compile-parser-quot [
+        dup [
+            dup remaining>> empty? [ drop f ] unless
+        ] when
+    ] compose ;
 
 : just ( parser -- parser )
     just-parser boa wrap-peg ;
@@ -102,7 +100,8 @@ PRIVATE>
     ! range of characters from the first to the second,
     ! inclusive.
     "^" ?head [
-        (range-pattern) '[ _ member? not ] satisfy
+        (range-pattern) dup length 1 =
+        [ first '[ _ = ] ] [ '[ _ member? ] ] if
     ] [
-        (range-pattern) '[ _ member? ] satisfy
-    ] if ;
+        [ [ not ] compose ] when satisfy
+    ] bi* ;