| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | USING: kernel arrays strings sequences sequences.deep accessors peg peg.ebnf | 
					
						
							|  |  |  |        newfx ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: shell.parser | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | TUPLE: basic-expr         command  stdin stdout background ;
 | 
					
						
							|  |  |  | TUPLE: pipeline-expr      commands stdin stdout background ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | TUPLE: single-quoted-expr expr ;
 | 
					
						
							|  |  |  | TUPLE: double-quoted-expr expr ;
 | 
					
						
							|  |  |  | TUPLE: back-quoted-expr   expr ;
 | 
					
						
							|  |  |  | TUPLE: glob-expr          expr ;
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | TUPLE: variable-expr      expr ;
 | 
					
						
							|  |  |  | TUPLE: factor-expr        expr ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | : 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 | 
					
						
							| 
									
										
										
										
											2008-05-16 18:09:38 -04:00
										 |  |  |     over 6th   >>stdout | 
					
						
							|  |  |  |     swap 7th   >>background ;
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : 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 ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | : ast>factor-expr ( ast -- obj ) 2nd >string factor-expr boa ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EBNF: expr | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | space = " " | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tab   = "\t" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | white = (space | tab) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | _ = (white)* => [[ drop ignore ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | sq = "'" | 
					
						
							|  |  |  | dq = '"' | 
					
						
							|  |  |  | bq = "`" | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | 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   ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | factor = "$(" (!(")") .)* ")" => [[ ast>factor-expr ]] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | variable = "$" other => [[ ast>variable-expr ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | glob-char = ("*" | "?") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | non-glob-char = !(glob-char | white) .
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | glob-beginning-string = (non-glob-char)* => [[ >string ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | glob-rest-string = (non-glob-char)+ => [[ >string ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ ast>glob-expr ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | other = (!(white | "&" | ">" | ">>" | "<" | "|") .)+ => [[ >string ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | element = (single-quoted | double-quoted | back-quoted | factor | variable | glob | other) | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | command = (element _)+ | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | to-file = ">"  _ other => [[ second ]] | 
					
						
							|  |  |  | in-file = "<"  _ other => [[ second ]] | 
					
						
							|  |  |  | ap-file = ">>" _ other => [[ second ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | basic = _ command _ (in-file)? _ (to-file | ap-file)? _ ("&")? => [[ ast>basic-expr ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | pipeline = _ command _ (in-file)? _ "|" _ (command _ "|" _)* command _ (to-file | ap-file)? _ ("&")? => [[ ast>pipeline-expr ]] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | submission = (pipeline | basic) | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | ;EBNF |