Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-04-17 20:01:22 -05:00
commit 6fb437c6d5
2 changed files with 36 additions and 16 deletions

View File

@ -14,6 +14,8 @@ TUPLE: double-quoted-expr expr ;
TUPLE: back-quoted-expr expr ; TUPLE: back-quoted-expr expr ;
TUPLE: glob-expr expr ; TUPLE: glob-expr expr ;
TUPLE: variable-expr expr ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: <single-quoted-expr> single-quoted-expr boa ; : <single-quoted-expr> single-quoted-expr boa ;
@ -45,6 +47,8 @@ bquote = "`"
back-quoted = bquote (!(bquote) .)* bquote => [[ second >string <back-quoted-expr> ]] back-quoted = bquote (!(bquote) .)* bquote => [[ second >string <back-quoted-expr> ]]
variable = "$" other => [[ second variable-expr boa ]]
glob-char = ("*" | "?") glob-char = ("*" | "?")
non-glob-char = !(glob-char | white) . non-glob-char = !(glob-char | white) .
@ -57,7 +61,7 @@ glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ fla
other = (!(white | "&" | ">" | ">>" | "<") .)+ => [[ >string ]] other = (!(white | "&" | ">" | ">>" | "<") .)+ => [[ >string ]]
element = (single-quoted | double-quoted | back-quoted | glob | other) element = (single-quoted | double-quoted | back-quoted | variable | glob | other)
to-file = ">" whitespace other => [[ second ]] to-file = ">" whitespace other => [[ second ]]

View File

@ -1,6 +1,6 @@
USING: kernel words continuations namespaces debugger sequences combinators USING: kernel words continuations namespaces debugger sequences combinators
io io.files io.launcher system io io.files io.launcher sequences.deep
accessors multi-methods newfx shell.parser ; accessors multi-methods newfx shell.parser ;
IN: shell IN: shell
@ -32,11 +32,20 @@ METHOD: expand { single-quoted-expr } expr>> ;
METHOD: expand { double-quoted-expr } expr>> ; METHOD: expand { double-quoted-expr } expr>> ;
METHOD: expand { variable-expr } expr>> os-env ;
METHOD: expand { glob-expr }
expr>>
dup "*" =
[ drop current-directory get directory [ first ] map ]
[ ]
if ;
METHOD: expand { object } ; METHOD: expand { object } ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: expansion ( command -- command ) [ expand ] map ; : expansion ( command -- command ) [ expand ] map flatten ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -67,20 +76,27 @@ METHOD: expand { object } ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: shell ( -- ) DEFER: shell
prompt
readln : handle ( input -- )
{ {
{ [ dup f = ] [ drop ] } { [ dup f = ] [ drop ] }
{ [ dup "exit" = ] [ drop ] } { [ dup "exit" = ] [ drop ] }
{ [ dup "" = ] [ drop shell ] } { [ dup "" = ] [ drop shell ] }
{ [ dup expr ] [ expr ast>> chant shell ] } { [ dup expr ] [ expr ast>> chant shell ] }
{ [ t ] [ drop shell ] } { [ t ] [ drop "ix: ignoring input" print shell ] }
} }
cond ; cond ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: shell ( -- )
prompt
readln
handle ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: ix ( -- ) shell ; : ix ( -- ) shell ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!