]> gitweb.factorcode.org Git - factor.git/commitdiff
peg: make a version that doesn't assert input was fully consumed
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 2 Jun 2023 18:57:43 +0000 (11:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 2 Jun 2023 18:57:43 +0000 (11:57 -0700)
basis/http/parsers/parsers.factor
basis/peg/peg.factor

index 720ecafa35d55816a4735df3b302a35da608806b..6b82bbaa3a5042e18ca5cee045112c8822116d6b 100644 (file)
@@ -71,7 +71,7 @@ IN: http.parsers
         space-parser ,
     ] seq* [ "1.0" suffix! ] action ;
 
-PEG: parse-request-line ( string -- triple )
+PARTIAL-PEG: parse-request-line ( string -- triple )
     ! Triple is { method url version }
     full-request-parser simple-request-parser 2array choice ;
 
@@ -84,7 +84,7 @@ PEG: parse-request-line ( string -- triple )
 : response-message-parser ( -- parser )
     text-parser repeat0 case-sensitive ;
 
-PEG: parse-response-line ( string -- triple )
+PARTIAL-PEG: parse-response-line ( string -- triple )
     ! Triple is { version code message }
     [
         space-parser ,
@@ -124,7 +124,7 @@ PEG: parse-response-line ( string -- triple )
     text-parser repeat0 case-sensitive
     2choice ;
 
-PEG: parse-header-line ( string -- pair )
+PARTIAL-PEG: parse-header-line ( string -- pair )
     ! Pair is either { name value } or { f value }. If f, its a
     ! continuation of the previous header line.
     [
@@ -163,7 +163,7 @@ PEG: parse-header-line ( string -- pair )
 : av-pairs-parser ( -- parser )
     av-pair-parser ";" token list-of optional ;
 
-PEG: (parse-set-cookie) ( string -- alist )
+PARTIAL-PEG: (parse-set-cookie) ( string -- alist )
     av-pairs-parser just [ sift ] action ;
 
 : cookie-value-parser ( -- parser )
@@ -179,6 +179,6 @@ PEG: (parse-set-cookie) ( string -- alist )
     [ ";,=" member? not ] satisfy repeat0 [ drop f ] action
     2choice ;
 
-PEG: (parse-cookie) ( string -- alist )
+PARTIAL-PEG: (parse-cookie) ( string -- alist )
     cookie-value-parser [ ";," member? ] satisfy list-of
     optional just [ sift ] action ;
index 4a095ed31bf30963f097602e0d077c846066180c..1ccd3ffda5053bee76e2e861cb581f74381cb717 100644 (file)
@@ -593,10 +593,12 @@ PRIVATE>
 
 ERROR: parse-failed input word ;
 
+SYNTAX: PARTIAL-PEG:
+    (:) [ ( -- parser ) memoize-quot '[ @ parse ] ] dip
+    define-declared ;
+
 SYNTAX: PEG:
-    (:) [
-        ( -- parser ) memoize-quot
-        '[ @ (parse) check-parse-result ast>> ]
-    ] dip define-declared ;
+    (:) [ ( -- parser ) memoize-quot '[ @ parse-fully ] ] dip
+    define-declared ;
 
 { "debugger" "peg" } "peg.debugger" require-when