Library
Module
Module type
Parameter
Class
Class type
Shell AST.
type 'a located = 'a Location.located
val equal_located :
'a. ('a -> 'a -> Ppx_deriving_runtime.bool) ->
'a located ->
'a located ->
Ppx_deriving_runtime.bool
val pp_located :
'a. (Ppx_deriving_runtime.Format.formatter ->
'a ->
Ppx_deriving_runtime.unit) ->
Ppx_deriving_runtime.Format.formatter ->
'a located ->
Ppx_deriving_runtime.unit
val show_located :
'a. (Ppx_deriving_runtime.Format.formatter ->
'a ->
Ppx_deriving_runtime.unit) ->
'a located ->
Ppx_deriving_runtime.string
Names in Shell are just strings with a few additional conditions.
The type word
is a description of words in Shell. See POSIX, 2 Shell & Utilities, 2.3 Token Recognition
and attribute =
| NoAttribute
| ParameterLength of word
| UseDefaultValues of word
| AssignDefaultValues of word
| IndicateErrorifNullorUnset of word
| UseAlternativeValue of word
| RemoveSmallestSuffixPattern of word
| RemoveLargestSuffixPattern of word
| RemoveSmallestPrefixPattern of word
| RemoveLargestPrefixPattern of word
and word_component =
| Literal of string
| DoubleQuoted of word
| Variable of name * attribute
| Subshell of program
| GlobAll
| GlobAny
| BracketExpression of Morbig.CST.bracket_expression
and word = word_component list
For now, a pattern
is just a word
.
and pattern = word list
An assignment is just a pair of a name
and a word
.
and assignment' = assignment located
A file descriptor descr
is an integer.
The following description does contain all the semantic subtleties of POSIX Shell. Such a description can be found in the document IEEE Std 1003.1™-2008, 2016 Edition. In the following, we will refer to it simple as POSIX.
The type command
contains the definition of a Shell command in Morsmall. Compared to what can be found in the POSIX standard or in Morbig, this type is rather small. This is because a lot of syntactically distinct scripts that are semantically equivalent are identified in here. For instance, all the following scripts are equivalent and identified as such:
if t1; then c1; elif t2; then c2; fi
if { t1; }; then c1; elif { { t2; }; }; fi
if t1; then c1; else if t2; then c2; fi; fi
See POSIX, 2 Shell & Utilities, 2.9.1 Simple Command
See POSIX, 2 Shell & Utilities, 2.9.2 Pipelines and 2.9.3 Lists
Async c
, the Shell shall execute c
asynchronously in a subshell. This means that the shell shall not wait for the command to finish before executing the next command.c1
and c2
in Seq (c1, c2)
shall be executed sequentially.And (c1, c2)
, c1
shall be executed first. If its exit status is zero, c2
shall be executed. The commands are expanded only if they are executed.Or (c1, c2)
, c1
shall be executed first. If its exit status is non-zero, c2
shall be executed.Pipe (c1, c2)
, the standard output of c1
shall be connected to the standard input of c2
. The standard input, standard output, or both of a command shall be considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command.Not c
has the same behaviour as c
, except for the exit status that shall be the logical NOT of the exit status of c
.See POSIX, 2 Shell & Utilities, 2.9.4 Compound Commands
Subshell c
shall execute c
a subshell environment. Variable assignments and built-in commands that affect the environment shall not remain in effect after the list finishes.For (x, l, c)
shall execute a sequence of commands c
for each member in a list of items. It is to be noted that l
is non-mandatory and is thus an option. Besides, there is an important semantic difference between None
and Some
[]
. The former appears in a for loop where the list of words appear but is empty. In that case, the for loops through the empty list. The latter appears in a for loop where the list of words has been omitted. In that case, the for loops through the positional parameters.Case (w, [([p11;...],c1);
...])
shall execute the compound-list corresponding to the first one of several patterns that is matched by the string resulting from the expansion of the given word w
. In order from the beginning to the end of the case statement, each pattern p*
shall be subjected to expansion, and the result of these expansions shall be compared against the expansion of w
. After the first match, no more patterns shall be expanded, and the corresponding c*
shall be executed. The order of expansion and comparison of multiple patterns that label the same statement is unspecified.If (c1, c2, c3)
shall execute c1
and use its exit status to determine whether to execute c2
or c3
. In fact, c3
is not mandatory and is thus an option.While (c1, c2)
shall continuously execute c2
as long as c1
has a zero exit status.Until (c1, c2)
shall continuously execute c2
as long as c1
has a non-zero exit status.See POSIX, 2 Shell & Utilities, 2.9.5 Function Definition Command
A function is a user-defined name that is used as a simple command to call a compound command with new positional parameters. A function is defined with a function definition command, Function (name, body)
.
This function definition command defines a function named name:
string
and with body body: command
. The body
shall be executed whenever name
is specified as the name of a simple command.
See POSIX, 2 Shell & Utilities, 2.7 Redirections
The type command
describes a command in the AST. All the command semantics are described at the top of this document.
and program = command' list
and command =
| Simple of assignment' list * word' list
| Async of command
| Seq of command' * command'
| And of command' * command'
| Or of command' * command'
| Not of command'
| Pipe of command' * command'
| Subshell of command'
| For of name * word list option * command'
| Case of word * case_item' list
| If of command' * command' * command' option
| While of command' * command'
| Until of command' * command'
| Function of name * command'
| Redirection of command' * descr * kind * word
| HereDocument of command' * descr * word'
val equal_name : name -> name -> Ppx_deriving_runtime.bool
val equal_character_range :
character_range ->
character_range ->
Ppx_deriving_runtime.bool
val equal_attribute : attribute -> attribute -> Ppx_deriving_runtime.bool
val equal_word_component :
word_component ->
word_component ->
Ppx_deriving_runtime.bool
val equal_word : word -> word -> Ppx_deriving_runtime.bool
val equal_word' : word' -> word' -> Ppx_deriving_runtime.bool
val equal_pattern : pattern -> pattern -> Ppx_deriving_runtime.bool
val equal_pattern' : pattern' -> pattern' -> Ppx_deriving_runtime.bool
val equal_assignment : assignment -> assignment -> Ppx_deriving_runtime.bool
val equal_assignment' : assignment' -> assignment' -> Ppx_deriving_runtime.bool
val equal_descr : descr -> descr -> Ppx_deriving_runtime.bool
val equal_program : program -> program -> Ppx_deriving_runtime.bool
val equal_command : command -> command -> Ppx_deriving_runtime.bool
val equal_command' : command' -> command' -> Ppx_deriving_runtime.bool
val equal_case_item : case_item -> case_item -> Ppx_deriving_runtime.bool
val equal_case_item' : case_item' -> case_item' -> Ppx_deriving_runtime.bool
val equal_kind : kind -> kind -> Ppx_deriving_runtime.bool
val pp_name :
Ppx_deriving_runtime.Format.formatter ->
name ->
Ppx_deriving_runtime.unit
val show_name : name -> Ppx_deriving_runtime.string
val pp_character_range :
Ppx_deriving_runtime.Format.formatter ->
character_range ->
Ppx_deriving_runtime.unit
val show_character_range : character_range -> Ppx_deriving_runtime.string
val pp_attribute :
Ppx_deriving_runtime.Format.formatter ->
attribute ->
Ppx_deriving_runtime.unit
val show_attribute : attribute -> Ppx_deriving_runtime.string
val pp_word_component :
Ppx_deriving_runtime.Format.formatter ->
word_component ->
Ppx_deriving_runtime.unit
val show_word_component : word_component -> Ppx_deriving_runtime.string
val pp_word :
Ppx_deriving_runtime.Format.formatter ->
word ->
Ppx_deriving_runtime.unit
val show_word : word -> Ppx_deriving_runtime.string
val pp_word' :
Ppx_deriving_runtime.Format.formatter ->
word' ->
Ppx_deriving_runtime.unit
val show_word' : word' -> Ppx_deriving_runtime.string
val pp_pattern :
Ppx_deriving_runtime.Format.formatter ->
pattern ->
Ppx_deriving_runtime.unit
val show_pattern : pattern -> Ppx_deriving_runtime.string
val pp_pattern' :
Ppx_deriving_runtime.Format.formatter ->
pattern' ->
Ppx_deriving_runtime.unit
val show_pattern' : pattern' -> Ppx_deriving_runtime.string
val pp_assignment :
Ppx_deriving_runtime.Format.formatter ->
assignment ->
Ppx_deriving_runtime.unit
val show_assignment : assignment -> Ppx_deriving_runtime.string
val pp_assignment' :
Ppx_deriving_runtime.Format.formatter ->
assignment' ->
Ppx_deriving_runtime.unit
val show_assignment' : assignment' -> Ppx_deriving_runtime.string
val pp_descr :
Ppx_deriving_runtime.Format.formatter ->
descr ->
Ppx_deriving_runtime.unit
val show_descr : descr -> Ppx_deriving_runtime.string
val pp_program :
Ppx_deriving_runtime.Format.formatter ->
program ->
Ppx_deriving_runtime.unit
val show_program : program -> Ppx_deriving_runtime.string
val pp_command :
Ppx_deriving_runtime.Format.formatter ->
command ->
Ppx_deriving_runtime.unit
val show_command : command -> Ppx_deriving_runtime.string
val pp_command' :
Ppx_deriving_runtime.Format.formatter ->
command' ->
Ppx_deriving_runtime.unit
val show_command' : command' -> Ppx_deriving_runtime.string
val pp_case_item :
Ppx_deriving_runtime.Format.formatter ->
case_item ->
Ppx_deriving_runtime.unit
val show_case_item : case_item -> Ppx_deriving_runtime.string
val pp_case_item' :
Ppx_deriving_runtime.Format.formatter ->
case_item' ->
Ppx_deriving_runtime.unit
val show_case_item' : case_item' -> Ppx_deriving_runtime.string
val pp_kind :
Ppx_deriving_runtime.Format.formatter ->
kind ->
Ppx_deriving_runtime.unit
val show_kind : kind -> Ppx_deriving_runtime.string
val default_redirection_descriptor : kind -> int