parser-combinators: refactor <*> and allow for promises to be implicitly forced in parsing

darcs
chris.double 2006-10-06 02:53:55 +00:00
parent 080430a386
commit ee67a9a92f
1 changed files with 4 additions and 9 deletions

View File

@ -7,6 +7,9 @@ IN: parser-combinators
! Parser combinator protocol ! Parser combinator protocol
GENERIC: (parse) ( input parser -- list ) GENERIC: (parse) ( input parser -- list )
M: promise (parse) ( input parser -- list )
force (parse) ;
: parse ( input parser -- promise ) : parse ( input parser -- promise )
[ (parse) ] curry curry <promise> ; [ (parse) ] curry curry <promise> ;
@ -186,16 +189,8 @@ M: some-parser (parse) ( input parser -- result )
#! Same as <&> except flatten the result. #! Same as <&> except flatten the result.
<&> [ dup second swap first [ , % ] { } make ] <@ ; <&> [ dup second swap first [ , % ] { } make ] <@ ;
DEFER: <*>
: (<*>) ( parser -- parser )
#! Non-delayed implementation of <*>
dup <*> <&:> [ ] succeed <|> ;
: <*> ( parser -- parser ) : <*> ( parser -- parser )
#! Return a parser that accepts zero or more occurences of the original [ dup <*> <&:> { } succeed <|> ] curry <promise> ;
#! parser.
[ (<*>) call ] curry ;
: (<+>) ( parser -- parser ) : (<+>) ( parser -- parser )
#! Non-delayed implementation of <+> #! Non-delayed implementation of <+>