From ee67a9a92f6cf77ef0fba289f8d388bc757e903f Mon Sep 17 00:00:00 2001 From: "chris.double" Date: Fri, 6 Oct 2006 02:53:55 +0000 Subject: [PATCH] parser-combinators: refactor <*> and allow for promises to be implicitly forced in parsing --- .../parser-combinators/parser-combinators.factor | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/contrib/parser-combinators/parser-combinators.factor b/contrib/parser-combinators/parser-combinators.factor index 14c7b8c0ae..38d5a9ed9b 100644 --- a/contrib/parser-combinators/parser-combinators.factor +++ b/contrib/parser-combinators/parser-combinators.factor @@ -7,6 +7,9 @@ IN: parser-combinators ! Parser combinator protocol GENERIC: (parse) ( input parser -- list ) +M: promise (parse) ( input parser -- list ) + force (parse) ; + : parse ( input parser -- promise ) [ (parse) ] curry curry ; @@ -186,16 +189,8 @@ M: some-parser (parse) ( input parser -- result ) #! Same as <&> except flatten the result. <&> [ dup second swap first [ , % ] { } make ] <@ ; -DEFER: <*> - -: (<*>) ( parser -- parser ) - #! Non-delayed implementation of <*> - dup <*> <&:> [ ] succeed <|> ; - : <*> ( parser -- parser ) - #! Return a parser that accepts zero or more occurences of the original - #! parser. - [ (<*>) call ] curry ; + [ dup <*> <&:> { } succeed <|> ] curry ; : (<+>) ( parser -- parser ) #! Non-delayed implementation of <+> -- 2.34.1