Gash Abstract Syntax Tree Specification
***************************************

Gash parses the shell language into an abstract syntax tree (AST) that
has the following form.

sync  ::= exp
        | ('<sh-async> exp)

exp   ::= pipe
        | ('<sh-and> exp1 exp2)
        | ('<sh-or> exp1 exp2)
        | ('<sh-not> pipe)

pipe  ::= cmd*
        | ('<sh-pipeline> cmd* ...)

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 ...)
        | ('<sh-begin> sync ...)

redir ::= ('> fdes word)
        | ('< fdes word)
        | ('>& fdes word)
        | ('<& fdes word)
        | ('>> fdes word)
        | ('<> fdes word)
        | ('>! fdes word)
        | ('<< fdes word)

Internally, the parser also uses these two forms:

        | ('<< fdes ('<sh-here-end> qword))
        | ('<<- fdes ('<sh-here-end> qword))

word  ::= string
        | (word ...)
        | ('<sh-quote> word)
        | ('<sh-cmd-sub> sync ...)
        | ('<sh-arithmetic> word)
        | ('<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)

var   ::= string
        | ("LINENO" integer)

The parser never returns a qword, but it is a useful notion.  It
gets used internally by the parser and by the `word' module.

qword ::= string
        | (qword ...)
        | ('<sh-quote> qword)

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.
