]> gitweb.factorcode.org Git - factor.git/commitdiff
peg: use memoize to simplify PEG: and allow it to reset properly
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 1 Jun 2023 03:47:16 +0000 (20:47 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 1 Jun 2023 03:47:16 +0000 (20:47 -0700)
basis/peg/peg.factor

index 4719d6e0dd8af6c49990e00c07e274e183bc289e..5d570678f630b14028981796095594602bc8ecdf 100644 (file)
@@ -2,9 +2,9 @@
 ! See https://factorcode.org/license.txt for BSD license.
 
 USING: accessors arrays assocs classes combinators
-combinators.short-circuit compiler.units effects.parser fry
-kernel make math math.order namespaces quotations sequences
-sets splitting unicode vectors vocabs.loader words ;
+combinators.short-circuit compiler.units effects.parser kernel
+make math math.order memoize.private namespaces quotations
+sequences sets splitting unicode vectors vocabs.loader words ;
 
 IN: peg
 
@@ -594,18 +594,9 @@ PRIVATE>
 ERROR: parse-failed input word ;
 
 SYNTAX: PEG:
-    [let
-        (:) :> ( word def effect )
-        [
-            [
-                def call compile :> compiled-def
-                word [
-                    [ compiled-def compiled-parse ]
-                    [ check-parse-result ast>> ]
-                    [ word parse-failed ] ?if
-                ] effect define-declared
-            ] with-compilation-unit
-        ] append!
-    ] ;
+    (:) [
+        f f 2array swap ( -- parser ) make/0
+        '[ @ (parse) check-parse-result ast>> ]
+    ] dip define-declared ;
 
 { "debugger" "peg" } "peg.debugger" require-when