Shasta was designed for libdash, with libbash support added later.
Both json_to_ast
(for libdash) and bash_to_shasta_ast
(for libbash) contain to_ast_node(s)
functions,
which each take a parsed, untyped AST and convert it to a shasta AST as defined in ast_node
.
Thr transformation is direct; bash is assumed to be a superset of dash. This is not strictly true, since
both have some minor divergences from the POSIX spec, but is good enough.
RedirectionNode
and*RedirNode
: Thefd
field is either('var', filename)
or('fixed', fd)
. Dash only uses the latter form; the first exists to support bashisms likeexec {fd} > log.txt
, which open the file and assignsfd
the new file descriptor.FileRedirNode
: 'ReadingString' subtype. Handles here-strings.BackgroundNode
: Theafter_ampersand
field. Handles an edge case with heredocs.
The pretty printer uses the various nobraces
and semicolon
fields to determine
whether braces and semicolons are printed. In dash, this doesn't matter, but in bash
they can lead to a syntax error. For example:
( { echo hi; echo bye } )
is invalid.
SelectNode
ArithNode
CondNode
ArithForNode
CoprocNode
TimeNode
SingleArgRedirNode
GroupNode