Language.Sh.Syntax
Description
Here we define the complete abstract syntax tree for simple and compound statements.
- data Command
- data AndOrList
- data Pipeline
- = Pipeline [Statement]
- | BangPipeline [Statement]
- data Term
- = TWord Word
- | TRedir Redir
- | TAssignment Assignment
- data Statement
- = Statement [Word] [Redir] [Assignment]
- | Compound CompoundStatement [Redir]
- | FunctionDefinition String CompoundStatement [Redir]
- | OrderedStatement [Term]
- data CompoundStatement
- type Word = [Lexeme]
- data Lexeme
- data Expansion
- data Redir
- data Assignment = String := Word
The statement level and above
Constructors
| Synchronous AndOrList | |
| Asynchronous AndOrList |
Constructors
| Pipeline [Statement] | |
| BangPipeline [Statement] |
Constructors
| TWord Word | |
| TRedir Redir | |
| TAssignment Assignment |
Constructors
| Statement [Word] [Redir] [Assignment] | |
| Compound CompoundStatement [Redir] | |
| FunctionDefinition String CompoundStatement [Redir] | |
| OrderedStatement [Term] |
data CompoundStatement Source
Constructors
| For String [Word] [Command] | |
| While [Command] [Command] | |
| Until [Command] [Command] | |
| If [Command] [Command] [Command] | |
| Case Word [([Word], [Command])] | |
| Subshell [Command] | |
| BraceGroup [Command] |
Instances
The word level and below
An expansion. The first three are all variable expansions. The
ModifiedExpansion in particular also keeps track of which operation
it is to perform. The Char can be any of -+=? and the Bool
says whether it was paired with a in the case of the first four
or doubled in the case of the latter two. This isn't a very good
data structure, but I hesitate to add 12 more algebraic types, one for
each type of expansion. It would be elegant to use a function
parameter here, but then we lose our data-ness and it makes it difficult
to be :Show. We could use a data class that has functions and is
also Show and can be pretty-printed, and this would allow arbitrary
generalizability, but do we really want this? It needs to be parsed
anyway. The other question is the bash extensions: do we parse for
/ or should it be an error? Is there a way to prevent it optionally?
data Assignment Source
Instances
| Show Assignment | |
| Pretty Assignment | |
| (Monad m, Functor m) => ExpressionMapperM m (Assignment -> m Assignment) | |
| ExpressionMapper (Assignment -> Assignment) |