From 827d0653a558903d5cb9f033c61cdc8bc423e9fd Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 19 Apr 2008 14:10:40 -0500 Subject: [PATCH] ix: Add syntax and implementation for executing inline Factor code --- extra/shell/parser/parser.factor | 9 ++++++--- extra/shell/shell.factor | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extra/shell/parser/parser.factor b/extra/shell/parser/parser.factor index c5c352c313..46548bb34f 100644 --- a/extra/shell/parser/parser.factor +++ b/extra/shell/parser/parser.factor @@ -39,6 +39,8 @@ TUPLE: factor-expr expr ; : ast>variable-expr ( ast -- obj ) 2nd variable-expr boa ; +: ast>factor-expr ( ast -- obj ) 2nd >string factor-expr boa ; + ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! EBNF: expr @@ -59,6 +61,8 @@ 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 ]] +factor = "$(" (!(")") .)* ")" => [[ ast>factor-expr ]] + variable = "$" other => [[ ast>variable-expr ]] glob-char = ("*" | "?") @@ -73,7 +77,7 @@ glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ ast other = (!(white | "&" | ">" | ">>" | "<" | "|") .)+ => [[ >string ]] -element = (single-quoted | double-quoted | back-quoted | variable | glob | other) +element = (single-quoted | double-quoted | back-quoted | factor | variable | glob | other) command = (element _)+ @@ -87,5 +91,4 @@ pipeline = _ command _ (in-file)? _ "|" _ (command _ "|" _)* command _ (to-file submission = (pipeline | basic) -;EBNF - +;EBNF \ No newline at end of file diff --git a/extra/shell/shell.factor b/extra/shell/shell.factor index 7482f388f1..57a7a7a327 100644 --- a/extra/shell/shell.factor +++ b/extra/shell/shell.factor @@ -1,5 +1,6 @@ -USING: kernel words continuations namespaces debugger sequences combinators +USING: kernel parser words continuations namespaces debugger + sequences combinators prettyprint system io io.files io.launcher sequences.deep accessors multi-methods newfx shell.parser ; @@ -41,6 +42,8 @@ METHOD: expand { glob-expr } [ ] if ; +METHOD: expand { factor-expr } expr>> eval unparse ; + METHOD: expand { object } ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -49,7 +52,8 @@ METHOD: expand { object } ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: run-sword ( basic-expr -- ) command>> unclip "shell" lookup execute ; +: run-sword ( basic-expr -- ) + command>> expansion unclip "shell" lookup execute ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!