]> gitweb.factorcode.org Git - factor.git/commitdiff
peg: move check-parse-result from peg.ebnf
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 31 May 2023 18:28:12 +0000 (11:28 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 31 May 2023 18:45:56 +0000 (11:45 -0700)
basis/peg/ebnf/ebnf.factor
basis/peg/peg.factor

index 27597a9d98e0433c2bb8c455e14faf0a6f8f02fe..4f03951b5015256505519eb70efdd3c3ecda97f3 100644 (file)
@@ -524,24 +524,8 @@ M: ebnf-non-terminal (transform)
     symbol>> parser get
     '[ _ dup _ at [ parser-not-found ] unless* nip ] box ;
 
-: transform-ebnf ( string -- object )
-    ebnf-parser parse transform ;
-
-ERROR: unable-to-fully-parse-ebnf remaining ;
-
-ERROR: could-not-parse-ebnf ;
-
-: check-parse-result ( result -- result )
-    [
-        dup remaining>> [ blank? ] trim [
-            unable-to-fully-parse-ebnf
-        ] unless-empty
-    ] [
-        could-not-parse-ebnf
-    ] if* ;
-
 : parse-ebnf ( string -- hashtable )
-    ebnf-parser (parse) check-parse-result ast>> transform ;
+    ebnf-parser parse-fully transform ;
 
 : ebnf>quot ( string -- hashtable quot: ( string -- results ) )
     parse-ebnf dup dup parser [ main of compile ] with-variable
index 275374a824f5c6a4b7bded6cae1d0203c72d59b1..4719d6e0dd8af6c49990e00c07e274e183bc289e 100644 (file)
@@ -322,6 +322,22 @@ SYMBOL: delayed
 : parse ( input parser -- ast )
     (parse) ast>> ;
 
+ERROR: unable-to-fully-parse remaining ;
+
+ERROR: could-not-parse ;
+
+: check-parse-result ( result -- result )
+    [
+        dup remaining>> [ blank? ] trim [
+            unable-to-fully-parse
+        ] unless-empty
+    ] [
+        could-not-parse
+    ] if* ;
+
+: parse-fully ( input parser -- ast )
+    (parse) check-parse-result ast>> ;
+
 <PRIVATE
 
 : next-id ( -- n )
@@ -585,7 +601,7 @@ SYNTAX: PEG:
                 def call compile :> compiled-def
                 word [
                     [ compiled-def compiled-parse ]
-                    [ ast>> ]
+                    [ check-parse-result ast>> ]
                     [ word parse-failed ] ?if
                 ] effect define-declared
             ] with-compilation-unit