2019-05-22 03:00:54 +01:00
|
|
|
Gash Abstract Syntax Tree Specification
|
|
|
|
***************************************
|
|
|
|
|
|
|
|
Gash parses the shell language into an abstract syntax tree (AST) that
|
|
|
|
has the following form.
|
|
|
|
|
2018-07-16 18:59:40 +01:00
|
|
|
sync ::= exp
|
|
|
|
| ('<sh-async> exp)
|
|
|
|
|
|
|
|
exp ::= pipe
|
2019-06-01 03:11:14 +01:00
|
|
|
| ('<sh-and> exp1 exp2)
|
|
|
|
| ('<sh-or> exp1 exp2)
|
2018-07-19 06:04:28 +01:00
|
|
|
| ('<sh-not> pipe)
|
2018-07-16 18:59:40 +01:00
|
|
|
|
|
|
|
pipe ::= cmd*
|
2018-07-19 06:19:00 +01:00
|
|
|
| ('<sh-pipeline> cmd* ...)
|
2018-07-16 18:59:40 +01:00
|
|
|
|
|
|
|
cmd* ::= cmd
|
|
|
|
| ('<sh-defun> name sync ...)
|
|
|
|
|
|
|
|
cmd ::= ('<sh-exec> word ...)
|
|
|
|
| ('<sh-exec-let> ((var var-word) ...) word ...)
|
|
|
|
| ('<sh-with-redirects> (redir ...) [cmd])
|
|
|
|
| ('<sh-set!> (var word) ...)
|
|
|
|
| ('<sh-subshell> sync ...)
|
|
|
|
| ('<sh-for> (name (word ...)) sync ...)
|
|
|
|
| ('<sh-case> word ((pattern-word ...) sync ...) ...)
|
|
|
|
| ('<sh-cond> (list sync ...) ... [('<sh-else> sync ...)])
|
|
|
|
| ('<sh-while> list sync ...)
|
|
|
|
| ('<sh-until> list sync ...)
|
2019-06-01 03:11:14 +01:00
|
|
|
| ('<sh-begin> sync ...)
|
2018-07-16 18:59:40 +01:00
|
|
|
|
|
|
|
redir ::= ('> fdes word)
|
|
|
|
| ('< fdes word)
|
|
|
|
| ('>& fdes word)
|
|
|
|
| ('<& fdes word)
|
|
|
|
| ('>> fdes word)
|
|
|
|
| ('<> fdes word)
|
|
|
|
| ('>! fdes word)
|
|
|
|
| ('<< fdes word)
|
2019-05-22 03:00:54 +01:00
|
|
|
|
|
|
|
Internally, the parser also uses these two forms:
|
|
|
|
|
2018-07-16 18:59:40 +01:00
|
|
|
| ('<< fdes ('<sh-here-end> qword))
|
|
|
|
| ('<<- fdes ('<sh-here-end> qword))
|
|
|
|
|
|
|
|
word ::= string
|
|
|
|
| (word ...)
|
|
|
|
| ('<sh-quote> word)
|
2019-06-01 03:11:14 +01:00
|
|
|
| ('<sh-cmd-sub> sync ...)
|
2018-07-16 18:59:40 +01:00
|
|
|
| ('<sh-ref> var)
|
|
|
|
| ('<sh-ref-or> var [word])
|
|
|
|
| ('<sh-ref-or*> var [word])
|
|
|
|
| ('<sh-ref-or!> var [word])
|
|
|
|
| ('<sh-ref-or!*> var [word])
|
|
|
|
| ('<sh-ref-assert> var [word])
|
|
|
|
| ('<sh-ref-assert*> var [word])
|
|
|
|
| ('<sh-ref-and> var [word])
|
|
|
|
| ('<sh-ref-and*> var [word])
|
|
|
|
| ('<sh-ref-except-min> var [word])
|
|
|
|
| ('<sh-ref-except-max> var [word])
|
|
|
|
| ('<sh-ref-skip-min> var [word])
|
|
|
|
| ('<sh-ref-skip-max> var [word])
|
|
|
|
| ('<sh-ref-length> var)
|
|
|
|
|
2019-06-01 03:11:14 +01:00
|
|
|
var ::= string
|
|
|
|
| ("LINENO" integer)
|
|
|
|
|
2019-05-22 03:00:54 +01:00
|
|
|
The parser never returns a qword, but it is a useful notion. It
|
|
|
|
gets used internally by the parser and by the `word' module.
|
|
|
|
|
2018-07-16 18:59:40 +01:00
|
|
|
qword ::= string
|
|
|
|
| (qword ...)
|
|
|
|
| ('<sh-quote> qword)
|
2019-05-22 03:00:54 +01:00
|
|
|
|
|
|
|
Copying this file
|
|
|
|
=================
|
|
|
|
|
|
|
|
Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
|
|
|
|
|
|
|
|
Copying and distribution of this file, with or without modification,
|
|
|
|
are permitted in any medium without royalty provided the copyright
|
|
|
|
notice and this notice are preserved. This file is offered as-is,
|
|
|
|
without any warranty.
|