language-bash-0.2.0: Parsing and pretty-printing Bash shell scripts

Safe HaskellSafe-Inferred

Language.Bash.Syntax

Contents

Description

Shell script types.

Synopsis

Syntax

Words

type Word = StringSource

A Bash word.

type Subscript = WordSource

A variable subscript [...].

Commands

data Command Source

A Bash command with redirections.

Constructors

Command ShellCommand [Redir] 

data Redir Source

A redirection.

Constructors

Redir

A redirection.

Fields

redirDesc :: Maybe IODesc

An optional file descriptor.

redirOp :: String

The redirection operator.

redirTarget :: Word

The redirection target.

Heredoc

A here document.

Fields

redirOp :: String

The redirection operator.

heredocDelim :: String

The here document delimiter.

heredocDelimQuoted :: Bool

True if the delimiter was quoted.

document :: String

The document itself.

data IODesc Source

A redirection file descriptor.

Constructors

IONumber Int

A file descriptor number.

IOVar String

A variable {varname} to allocate a file descriptor for.

data ShellCommand Source

A Bash command.

Constructors

SimpleCommand [Assign] [Word]

A simple command consisting of assignments followed by words.

AssignBuiltin Word [Either Assign Word]

The shell builtins declare, eval, export, local, readonly, and typeset can accept both assignments and words as arguments.

FunctionDef String List

A function name and definition.

Coproc String Command

A named coprocess.

Subshell List

A (...) list, denoting a subshell.

Group List

A {...} list.

Arith String

An arithmetic expression.

Cond [Word]

A Bash [[...]] conditional expression.

For Word [Word] List

A for word in words command. If in words is absent, the word list defaults to "$@".

ArithFor String List

An arithmetic for ((...)) command.

Select Word [Word] List

A select word in words command. If in words is absent, the word list defaults to "$@".

Case Word [CaseClause]

A case command.

If List List (Maybe List)

An if command, with a predicate, consequent, and alternative. elif clauses are parsed as nested if statements.

Until List List

An until command.

While List List

A while command.

data CaseClause Source

A single case clause.

Constructors

CaseClause [Word] List CaseTerm 

data CaseTerm Source

A case clause terminator.

Constructors

Break

The ;; operator.

FallThrough

The ;& operator.

Continue

The ;;& operator.

Lists

newtype List Source

A compound list of statements.

Constructors

List [Statement] 

data Statement Source

A single statement in a list.

Constructors

Statement AndOr ListTerm 

data ListTerm Source

A statement terminator.

Constructors

Sequential

The ; operator.

Asynchronous

The & operator.

data AndOr Source

A right-associative list of pipelines.

Constructors

Last Pipeline

The last pipeline of a list.

And Pipeline AndOr

An && construct.

Or Pipeline AndOr

An || construct.

data Pipeline Source

A (possibly timed or inverted) pipeline, linked with | or |&.

Constructors

Pipeline 

Fields

timed :: Bool

True if the pipeline is timed with time.

timedPosix :: Bool

True if the pipeline is timed with the -p flag.

inverted :: Bool

True if the pipeline is inverted with !.

commands :: [Command]

A list of commands, separated by |, or |&. command1 |& command2 is treated as a shorthand for command1 2>&1 | command2.

Assignments

data Assign Source

An assignment.

data LValue Source

The left side of an assignment.

Constructors

LValue String (Maybe Subscript) 

data AssignOp Source

An assignment operator.

Constructors

Equals

The = operator.

PlusEquals

The += operator.

data RValue Source

The right side of an assignment.

Constructors

RValue Word

A simple word.

RArray [(Maybe Subscript, Word)]

An array assignment.

Syntax elements

reservedWords :: [Word]Source

Shell reserved words.

assignBuiltins :: [Word]Source

Shell assignment builtins. These builtins can take assignments as arguments.

redirOps :: [String]Source

Redirection operators, not including here document operators.

heredocOps :: [String]Source

Here document operators.

controlOps :: [String]Source

Shell control operators.

normalOps :: [String]Source

All normal operators.