2 USING: kernel arrays strings sequences sequences.deep accessors peg peg.ebnf
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 TUPLE: basic-expr command stdin stdout background ;
10 TUPLE: pipeline-expr commands stdin stdout background ;
11 TUPLE: single-quoted-expr expr ;
12 TUPLE: double-quoted-expr expr ;
13 TUPLE: back-quoted-expr expr ;
14 TUPLE: glob-expr expr ;
15 TUPLE: variable-expr expr ;
16 TUPLE: factor-expr expr ;
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 : ast>basic-expr ( ast -- obj ) first4 basic-expr boa ;
22 : ast>pipeline-expr ( ast -- obj )
24 over [ 1st ] [ 4th [ 1st ] map ] [ 5th ] tri suffix prefix-on >>commands
27 swap 7th >>background ;
29 : ast>single-quoted-expr ( ast -- obj )
30 2nd >string single-quoted-expr boa ;
32 : ast>double-quoted-expr ( ast -- obj )
33 2nd >string double-quoted-expr boa ;
35 : ast>back-quoted-expr ( ast -- obj )
36 2nd >string back-quoted-expr boa ;
38 : ast>glob-expr ( ast -- obj ) flatten concat glob-expr boa ;
40 : ast>variable-expr ( ast -- obj ) 2nd variable-expr boa ;
42 : ast>factor-expr ( ast -- obj ) 2nd >string factor-expr boa ;
44 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
54 _ = (white)* => [[ drop ignore ]]
60 single-quoted = sq (!(sq) .)* sq => [[ ast>single-quoted-expr ]]
61 double-quoted = dq (!(dq) .)* dq => [[ ast>double-quoted-expr ]]
62 back-quoted = bq (!(bq) .)* bq => [[ ast>back-quoted-expr ]]
64 factor = "$(" (!(")") .)* ")" => [[ ast>factor-expr ]]
66 variable = "$" other => [[ ast>variable-expr ]]
68 glob-char = ("*" | "?")
70 non-glob-char = !(glob-char | white) .
72 glob-beginning-string = (non-glob-char)* => [[ >string ]]
74 glob-rest-string = (non-glob-char)+ => [[ >string ]]
76 glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ ast>glob-expr ]]
78 other = (!(white | "&" | ">" | ">>" | "<" | "|") .)+ => [[ >string ]]
80 element = (single-quoted | double-quoted | back-quoted | factor | variable | glob | other)
82 command = (element _)+
84 to-file = ">" _ other => [[ second ]]
85 in-file = "<" _ other => [[ second ]]
86 ap-file = ">>" _ other => [[ second ]]
88 basic = _ command _ (in-file)? _ (to-file | ap-file)? _ ("&")? => [[ ast>basic-expr ]]
90 pipeline = _ command _ (in-file)? _ "|" _ (command _ "|" _)* command _ (to-file | ap-file)? _ ("&")? => [[ ast>pipeline-expr ]]
92 submission = (pipeline | basic)