From 1b836450979c8422d682e609f3541930402dc36a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 18 Apr 2008 13:42:56 -0500 Subject: [PATCH 1/4] error check run process related words in docs use ERROR: --- extra/editors/vim/vim.factor | 2 +- extra/io/launcher/launcher-docs.factor | 3 +++ extra/io/launcher/launcher.factor | 5 +---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extra/editors/vim/vim.factor b/extra/editors/vim/vim.factor index 8d60942d67..f632a478be 100755 --- a/extra/editors/vim/vim.factor +++ b/extra/editors/vim/vim.factor @@ -18,7 +18,7 @@ M: vim vim-command ( file line -- array ) : vim-location ( file line -- ) vim-command vim-detach get-global - [ run-detached ] [ run-process ] if drop ; + [ try-detached ] [ try-process ] if ; "vim" vim-path set-global [ vim-location ] edit-hook set-global diff --git a/extra/io/launcher/launcher-docs.factor b/extra/io/launcher/launcher-docs.factor index 4446b82f20..dadb627fc0 100755 --- a/extra/io/launcher/launcher-docs.factor +++ b/extra/io/launcher/launcher-docs.factor @@ -113,6 +113,8 @@ HELP: try-process { $values { "desc" "a launch descriptor" } } { $description "Launches a process and waits for it to complete. If it exits with a non-zero status code, throws a " { $link process-failed } " error." } ; +{ run-process try-process run-detached } related-words + HELP: kill-process { $values { "process" process } } { $description "Kills a running process. Does nothing if the process has already exited." } ; @@ -171,6 +173,7 @@ ARTICLE: "io.launcher.launch" "Launching processes" "Launching processes:" { $subsection run-process } { $subsection try-process } +{ $subsection run-detached } "Redirecting standard input and output to a pipe:" { $subsection } { $subsection with-process-stream } ; diff --git a/extra/io/launcher/launcher.factor b/extra/io/launcher/launcher.factor index 9b480d0cc2..6ee8660528 100755 --- a/extra/io/launcher/launcher.factor +++ b/extra/io/launcher/launcher.factor @@ -127,10 +127,7 @@ HOOK: run-process* io-backend ( process -- handle ) run-detached dup detached>> [ dup wait-for-process drop ] unless ; -TUPLE: process-failed code ; - -: process-failed ( code -- * ) - \ process-failed boa throw ; +ERROR: process-failed code ; : try-process ( desc -- ) run-process wait-for-process dup zero? From 8635a0ee2fe52ea0c1455d844a2d79a9611e2d1d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 18 Apr 2008 14:02:11 -0500 Subject: [PATCH 2/4] vim should work again --- extra/editors/vim/vim.factor | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extra/editors/vim/vim.factor b/extra/editors/vim/vim.factor index f632a478be..9ce256868b 100755 --- a/extra/editors/vim/vim.factor +++ b/extra/editors/vim/vim.factor @@ -1,5 +1,5 @@ USING: definitions io io.launcher kernel math math.parser -namespaces parser prettyprint sequences editors ; +namespaces parser prettyprint sequences editors accessors ; IN: editors.vim SYMBOL: vim-path @@ -17,8 +17,9 @@ M: vim vim-command ( file line -- array ) : vim-location ( file line -- ) vim-command - vim-detach get-global - [ try-detached ] [ try-process ] if ; + swap >>command + vim-detach get-global [ t >>detached ] when + try-process ; "vim" vim-path set-global [ vim-location ] edit-hook set-global From 6edac99d83e5fc594b3ce4451d0095d92cbbd6d4 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Fri, 18 Apr 2008 19:22:53 -0500 Subject: [PATCH 3/4] newfx: minor additions --- extra/newfx/newfx.factor | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/extra/newfx/newfx.factor b/extra/newfx/newfx.factor index 6a191f0e07..3e5f66eb6f 100644 --- a/extra/newfx/newfx.factor +++ b/extra/newfx/newfx.factor @@ -155,6 +155,23 @@ METHOD: as-mutate { object object assoc } set-at ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +: prefix-on ( elt seq -- seq ) swap prefix ; +: suffix-on ( elt seq -- seq ) swap suffix ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: 1st 0 at ; +: 2nd 1 at ; +: 3rd 2 at ; +: 4th 3 at ; +: 5th 4 at ; +: 6th 5 at ; +: 7th 6 at ; +: 8th 7 at ; +: 9th 8 at ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ! A note about the 'mutate' qualifier. Other words also technically mutate ! their primary object. However, the 'mutate' qualifier is supposed to ! indicate that this is the main objective of the word, as a side effect. \ No newline at end of file From 0fd4acb85e7ca2665bfd92dd78396d9e90565ee5 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Fri, 18 Apr 2008 19:23:30 -0500 Subject: [PATCH 4/4] shell: Add pipeline syntax --- extra/shell/parser/parser.factor | 78 +++++++++++++++++++------------- extra/shell/shell.factor | 34 +++++++++++--- 2 files changed, 74 insertions(+), 38 deletions(-) diff --git a/extra/shell/parser/parser.factor b/extra/shell/parser/parser.factor index 4e3ae8069c..c5c352c313 100644 --- a/extra/shell/parser/parser.factor +++ b/extra/shell/parser/parser.factor @@ -1,27 +1,43 @@ -USING: kernel arrays strings sequences sequences.deep peg peg.ebnf ; +USING: kernel arrays strings sequences sequences.deep accessors peg peg.ebnf + newfx ; IN: shell.parser ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -TUPLE: incantation command stdin stdout background ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - +TUPLE: basic-expr command stdin stdout background ; +TUPLE: pipeline-expr commands stdin stdout background ; TUPLE: single-quoted-expr expr ; TUPLE: double-quoted-expr expr ; TUPLE: back-quoted-expr expr ; TUPLE: glob-expr expr ; - -TUPLE: variable-expr expr ; +TUPLE: variable-expr expr ; +TUPLE: factor-expr expr ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: single-quoted-expr boa ; -: double-quoted-expr boa ; -: back-quoted-expr boa ; -: glob-expr boa ; +: ast>basic-expr ( ast -- obj ) first4 basic-expr boa ; + +: ast>pipeline-expr ( ast -- obj ) + pipeline-expr new + over [ 1st ] [ 4th [ 1st ] map ] [ 5th ] tri suffix prefix-on >>commands + over 2nd >>stdin + over 5th >>stdout + swap 6th >>background ; + +: ast>single-quoted-expr ( ast -- obj ) + 2nd >string single-quoted-expr boa ; + +: ast>double-quoted-expr ( ast -- obj ) + 2nd >string double-quoted-expr boa ; + +: ast>back-quoted-expr ( ast -- obj ) + 2nd >string back-quoted-expr boa ; + +: ast>glob-expr ( ast -- obj ) flatten concat glob-expr boa ; + +: ast>variable-expr ( ast -- obj ) 2nd variable-expr boa ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -33,45 +49,43 @@ tab = "\t" white = (space | tab) -whitespace = (white)* => [[ drop ignore ]] +_ = (white)* => [[ drop ignore ]] -squote = "'" +sq = "'" +dq = '"' +bq = "`" -single-quoted = squote (!(squote) .)* squote => [[ second >string ]] +single-quoted = sq (!(sq) .)* sq => [[ ast>single-quoted-expr ]] +double-quoted = dq (!(dq) .)* dq => [[ ast>double-quoted-expr ]] +back-quoted = bq (!(bq) .)* bq => [[ ast>back-quoted-expr ]] -dquote = '"' - -double-quoted = dquote (!(dquote) .)* dquote => [[ second >string ]] - -bquote = "`" - -back-quoted = bquote (!(bquote) .)* bquote => [[ second >string ]] - -variable = "$" other => [[ second variable-expr boa ]] +variable = "$" other => [[ ast>variable-expr ]] glob-char = ("*" | "?") non-glob-char = !(glob-char | white) . -glob-beginning-string = (non-glob-char)* [[ >string ]] +glob-beginning-string = (non-glob-char)* => [[ >string ]] -glob-rest-string = (non-glob-char)+ [[ >string ]] +glob-rest-string = (non-glob-char)+ => [[ >string ]] -glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ flatten concat ]] +glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ ast>glob-expr ]] -other = (!(white | "&" | ">" | ">>" | "<") .)+ => [[ >string ]] +other = (!(white | "&" | ">" | ">>" | "<" | "|") .)+ => [[ >string ]] element = (single-quoted | double-quoted | back-quoted | variable | glob | other) -to-file = ">" whitespace other => [[ second ]] +command = (element _)+ -in-file = "<" whitespace other => [[ second ]] +to-file = ">" _ other => [[ second ]] +in-file = "<" _ other => [[ second ]] +ap-file = ">>" _ other => [[ second ]] -ap-file = ">>" whitespace other => [[ second ]] +basic = _ command _ (in-file)? _ (to-file | ap-file)? _ ("&")? => [[ ast>basic-expr ]] -redirection = (in-file)? whitespace (to-file | ap-file)? +pipeline = _ command _ (in-file)? _ "|" _ (command _ "|" _)* command _ (to-file | ap-file)? _ ("&")? => [[ ast>pipeline-expr ]] -line = (element whitespace)+ (in-file)? whitespace (to-file | ap-file)? whitespace ("&")? => [[ first4 incantation boa ]] +submission = (pipeline | basic) ;EBNF diff --git a/extra/shell/shell.factor b/extra/shell/shell.factor index f36b6f6400..7482f388f1 100644 --- a/extra/shell/shell.factor +++ b/extra/shell/shell.factor @@ -49,22 +49,44 @@ METHOD: expand { object } ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: run-incantation ( incantation -- ) +: run-sword ( basic-expr -- ) command>> unclip "shell" lookup execute ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: run-foreground ( process -- ) + [ try-process ] [ print-error drop ] recover ; + +: run-background ( process -- ) run-detached drop ; + +: run-basic-expr ( basic-expr -- ) over command>> expansion >>command over stdin>> >>stdin over stdout>> >>stdout swap background>> - [ run-detached drop ] - [ [ try-process ] [ print-error drop ] recover ] + [ run-background ] + [ run-foreground ] if ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: chant ( incantation -- ) +: basic-chant ( basic-expr -- ) dup command>> first swords member-of? - [ command>> unclip "shell" lookup execute ] - [ run-incantation ] + [ run-sword ] + [ run-basic-expr ] + if ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: pipeline-chant ( pipeline-chant -- ) + drop "ix: pipelines not supported" print ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: chant ( obj -- ) + dup basic-expr? + [ basic-chant ] + [ pipeline-chant ] if ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!