From 855b7009c84aacbf878eb36cb3b6fa86c912d3a7 Mon Sep 17 00:00:00 2001 From: "chris.double" Date: Mon, 7 Aug 2006 04:35:48 +0000 Subject: [PATCH] parser-combinators: Fix <:&> and add <&:> --- .../parser-combinators/parser-combinators.factor | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/contrib/parser-combinators/parser-combinators.factor b/contrib/parser-combinators/parser-combinators.factor index 2ed44f0630..feea1b6cc4 100644 --- a/contrib/parser-combinators/parser-combinators.factor +++ b/contrib/parser-combinators/parser-combinators.factor @@ -20,7 +20,7 @@ ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -USING: lazy-lists kernel sequences strings math io arrays errors ; +USING: lazy-lists kernel sequences strings math io arrays errors namespaces ; IN: parser-combinators TUPLE: parse-result parsed unparsed ; @@ -232,17 +232,25 @@ TUPLE: parse-result parsed unparsed ; : <:&>-parser ( input parser1 parser2 -- result ) #! Same as <&> except flatten the result. - <&> [ flatten ] <@ call ; + <&> [ dup second swap first [ % , ] { } make ] <@ call ; : <:&> ( parser1 parser2 -- parser ) #! Same as <&> except flatten the result. [ <:&>-parser ] curry curry ; +: <&:>-parser ( input parser1 parser2 -- result ) + #! Same as <&> except flatten the result. + <&> [ dup second swap first [ , % ] { } make ] <@ call ; + +: <&:> ( parser1 parser2 -- parser ) + #! Same as <&> except flatten the result. + [ <&:>-parser ] curry curry ; + DEFER: <*> : (<*>) ( parser -- parser ) #! Non-delayed implementation of <*> - dup <*> <:&> [ ] succeed <|> ; + dup <*> <&:> [ ] succeed <|> ; : <*> ( parser -- parser ) #! Return a parser that accepts zero or more occurences of the original @@ -251,7 +259,7 @@ DEFER: <*> : (<+>) ( parser -- parser ) #! Non-delayed implementation of <+> - dup <*> <:&> ; + dup <*> <&:> ; : <+> ( parser -- parser ) #! Return a parser that accepts one or more occurences of the original