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 IN: temporary
USING: io.unix.launcher tools.test ; USING: io.unix.launcher tools.test ;
[ { } ] [ "" tokenize-command ] unit-test [ "" tokenize-command ] unit-test-fails
[ { } ] [ " " tokenize-command ] unit-test [ " " tokenize-command ] unit-test-fails
[ { "a" } ] [ "a" tokenize-command ] unit-test [ { "a" } ] [ "a" tokenize-command ] unit-test
[ { "abc" } ] [ "abc" tokenize-command ] unit-test [ { "abc" } ] [ "abc" 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 <|> ; inline
LAZY: 'quoted' ( delimiter -- parser ) 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 ) LAZY: 'argument' ( -- parser )
"\"" 'quoted' "'" 'quoted' 'unquoted' <|> <|> "\"" 'quoted' "'" 'quoted' 'unquoted' <|> <|>
[ >string ] <@ ; [ >string ] <@ ;
MEMO: 'arguments' ( -- parser ) : 'arguments' ( -- parser )
'argument' " " token <+> list-of ; 'argument' " " token <!+> nonempty-list-of ;
: tokenize-command ( command -- arguments ) : tokenize-command ( command -- arguments )
'arguments' parse-1 ; 'arguments' just parse-1 ;
: get-arguments ( -- seq ) : get-arguments ( -- seq )
+command+ get [ tokenize-command ] [ +arguments+ get ] if* ; +command+ get [ tokenize-command ] [ +arguments+ get ] if* ;

View File

@ -246,18 +246,21 @@ LAZY: <(+)> ( parser -- parser )
#! Implementation by Matthew Willis. #! Implementation by Matthew Willis.
dup <(*)> <&:> ; dup <(*)> <&:> ;
LAZY: pack ( close body open -- parser ) : pack ( close body open -- parser )
#! Parse a construct enclosed by two symbols, #! Parse a construct enclosed by two symbols,
#! given a parser for the opening symbol, the #! given a parser for the opening symbol, the
#! closing symbol, and the body. #! 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 #! Given a parser for the separator and for the
#! items themselves, return a parser that parses #! items themselves, return a parser that parses
#! lists of those items. The parse tree is an #! lists of those items. The parse tree is an
#! array of the parsed items. #! array of the parsed items.
dup <?> -rot over &> <*> <&:> &> { } succeed <|> ; nonempty-list-of { } succeed <|> ;
LAZY: surrounded-by ( parser start end -- parser' ) LAZY: surrounded-by ( parser start end -- parser' )
[ token ] 2apply swapd pack ; [ token ] 2apply swapd pack ;