]> gitweb.factorcode.org Git - factor.git/commitdiff
parser-combinators: refactor 'sp' and 'just'
authorchris.double <chris.double@double.co.nz>
Fri, 6 Oct 2006 01:28:01 +0000 (01:28 +0000)
committerchris.double <chris.double@double.co.nz>
Fri, 6 Oct 2006 01:28:01 +0000 (01:28 +0000)
contrib/parser-combinators/parser-combinators.factor

index b16a301d9ed43e5747af4f5142280639ab02945e..a304b8628cad177e717b0d960b14239dffa1cc6c 100644 (file)
@@ -114,28 +114,31 @@ M: or-parser (parse) ( input parser1 -- list )
 : string-ltrim ( string -- string )
   #! Return a new string without any leading whitespace
   #! from the original string.
-  dup first blank? [ 1 tail string-ltrim ] when ;
+  dup first blank? [ 1 tail-slice string-ltrim ] when ;
 
-: sp-parser ( input parser -- result )
-  #! Skip all leading whitespace from the input then call
-  #! the parser on the remaining input.
-  >r string-ltrim r> call ;
+TUPLE: sp-parser p1 ;
 
-: sp ( parser -- parser )
+: sp ( p1 -- parser )
   #! Return a parser that first skips all whitespace before
   #! calling the original parser.
-  [ sp-parser ] curry ;
+  <sp-parser> ;
+
+M: sp-parser (parse) ( input parser -- list )
+  #! Skip all leading whitespace from the input then call
+  #! the parser on the remaining input.
+  >r string-ltrim r> sp-parser-p1 parse ;
+
+TUPLE: just-parser p1 ;
 
-: just-parser ( input parser -- result )
+: just ( p1 -- parser )
+  <just-parser> ;
+
+M: just-parser (parse) ( input parser -- result )
   #! Calls the given parser on the input removes
   #! from the results anything where the remaining
   #! input to be parsed is not empty. So ensures a 
   #! fully parsed input string.
-  call [ parse-result-unparsed empty? ] lsubset ;
-
-: just ( parser -- parser )
-  #! Return an instance of the just-parser.
-  [ just-parser ] curry ;
+  just-parser-p1 parse [ parse-result-unparsed empty? ] lsubset ;
 
 : <@-parser ( input parser quot -- result )
   #! Calls the parser on the input. For each successfull