Merge git://factorcode.org/git/factor

release
Doug Coleman 2007-11-24 19:20:19 -06:00
commit 30d3e5bd2d
3 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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* ;

View File

@ -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 ;
[ token ] 2apply swapd pack ;