Clean up io.unix.launcher command parser

release
Slava Pestov 2007-11-24 19:37:21 -05:00
parent 82e98dac8b
commit 026c4186f1
2 changed files with 24 additions and 11 deletions

View File

@ -16,4 +16,18 @@ USING: io.unix.launcher tools.test ;
[ { "abc def" "hey" } ] [ "'abc def' \"hey\"" tokenize-command ] unit-test
[ "'abc def' \"hey" tokenize-command ] unit-test-fails
[ "'abc def" tokenize-command ] unit-test-fails
[ { "abc def" "h\"ey" } ] [ "'abc def' \"h\"ey\" " tokenize-command ] unit-test
[ { "abc def" "h\"ey" } ] [ "'abc def' \"h\\\"ey\" " tokenize-command ] unit-test
[
{
"Hello world.app/Contents/MacOS/hello-ui"
"-i=boot.macosx-ppc.image"
"-include= math compiler ui"
"-deploy-vocab=hello-ui"
"-output-image=Hello world.app/Contents/Resources/hello-ui.image"
"-no-stack-traces"
"-no-user-init"
}
] [
"\"Hello world.app/Contents/MacOS/hello-ui\" -i=boot.macosx-ppc.image \"-include= math compiler ui\" -deploy-vocab=hello-ui \"-output-image=Hello world.app/Contents/Resources/hello-ui.image\" -no-stack-traces -no-user-init" tokenize-command
] unit-test

View File

@ -16,19 +16,18 @@ USE: unix
! "foo bar" -- quotation
LAZY: 'escaped-char' "\\" token any-char-parser &> ;
LAZY: 'chars' 'escaped-char' any-char-parser <|> <*> ;
LAZY: 'quoted-char' ( delimiter -- parser' )
'escaped-char'
swap [ member? not ] curry satisfy
<|> ; inline
LAZY: 'quoted-1' 'chars' "\"" "\"" surrounded-by ;
LAZY: 'quoted' ( delimiter -- parser )
dup 'quoted-char' <*> swap dup surrounded-by ;
LAZY: 'quoted-2' 'chars' "'" "'" surrounded-by ;
LAZY: 'unquoted' ( -- parser ) " " 'quoted-char' <+> ;
LAZY: 'non-space-char'
'escaped-char' [ CHAR: \s = not ] satisfy <|> ;
LAZY: 'unquoted' 'non-space-char' <+> ;
LAZY: 'argument'
'quoted-1' 'quoted-2' 'unquoted' <|> <|>
LAZY: 'argument' ( -- parser )
"\"" 'quoted' "'" 'quoted' 'unquoted' <|> <|>
[ >string ] <@ ;
MEMO: 'arguments' ( -- parser )