From 72fe4e2d70a498ff1c1069fda3d008251b7cfb9e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 24 Nov 2007 20:19:39 -0500 Subject: [PATCH] clean up io.unix.launcher parser, and parser-combinators --- extra/io/unix/launcher/launcher-tests.factor | 4 ++-- extra/io/unix/launcher/launcher.factor | 10 +++++----- extra/parser-combinators/parser-combinators.factor | 11 +++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/extra/io/unix/launcher/launcher-tests.factor b/extra/io/unix/launcher/launcher-tests.factor index 88f467385a..fec97baa5a 100755 --- a/extra/io/unix/launcher/launcher-tests.factor +++ b/extra/io/unix/launcher/launcher-tests.factor @@ -1,8 +1,8 @@ IN: temporary USING: io.unix.launcher tools.test ; -[ { } ] [ "" tokenize-command ] unit-test -[ { } ] [ " " tokenize-command ] unit-test +[ "" tokenize-command ] unit-test-fails +[ " " tokenize-command ] unit-test-fails [ { "a" } ] [ "a" tokenize-command ] unit-test [ { "abc" } ] [ "abc" tokenize-command ] unit-test [ { "abc" } ] [ "abc " tokenize-command ] unit-test diff --git a/extra/io/unix/launcher/launcher.factor b/extra/io/unix/launcher/launcher.factor index 322bef7e7f..4cf8f8b8d4 100755 --- a/extra/io/unix/launcher/launcher.factor +++ b/extra/io/unix/launcher/launcher.factor @@ -22,19 +22,19 @@ LAZY: 'quoted-char' ( delimiter -- parser' ) <|> ; inline LAZY: 'quoted' ( delimiter -- parser ) - dup 'quoted-char' <*> swap dup surrounded-by ; + dup 'quoted-char' swap dup surrounded-by ; -LAZY: 'unquoted' ( -- parser ) " " 'quoted-char' <+> ; +LAZY: 'unquoted' ( -- parser ) " '\"" 'quoted-char' ; LAZY: 'argument' ( -- parser ) "\"" 'quoted' "'" 'quoted' 'unquoted' <|> <|> [ >string ] <@ ; -MEMO: 'arguments' ( -- parser ) - 'argument' " " token <+> list-of ; +: 'arguments' ( -- parser ) + 'argument' " " token nonempty-list-of ; : tokenize-command ( command -- arguments ) - 'arguments' parse-1 ; + 'arguments' just parse-1 ; : get-arguments ( -- seq ) +command+ get [ tokenize-command ] [ +arguments+ get ] if* ; diff --git a/extra/parser-combinators/parser-combinators.factor b/extra/parser-combinators/parser-combinators.factor index 6301f778f5..5741c801f7 100755 --- a/extra/parser-combinators/parser-combinators.factor +++ b/extra/parser-combinators/parser-combinators.factor @@ -246,18 +246,21 @@ LAZY: <(+)> ( parser -- parser ) #! Implementation by Matthew Willis. dup <(*)> <&:> ; -LAZY: pack ( close body open -- parser ) +: pack ( close body open -- parser ) #! Parse a construct enclosed by two symbols, #! given a parser for the opening symbol, the #! closing symbol, and the body. <& &> ; -LAZY: list-of ( items separator -- parser ) +: nonempty-list-of ( items separator -- parser ) + [ over &> <*> <&:> ] keep tuck pack ; + +: list-of ( items separator -- parser ) #! Given a parser for the separator and for the #! items themselves, return a parser that parses #! lists of those items. The parse tree is an #! array of the parsed items. - dup -rot over &> <*> <&:> &> { } succeed <|> ; + nonempty-list-of { } succeed <|> ; LAZY: surrounded-by ( parser start end -- parser' ) - [ token ] 2apply swapd pack ; \ No newline at end of file + [ token ] 2apply swapd pack ; \ No newline at end of file