module CST:sig
..end
The type for concrete syntax trees of POSIX shell scripts. These trees are produced by the Morbig parser.
These type definitions refer directly to the grammar production
rules of the POSIX standard. We use the following convention to
name data constructors: given a rule A -> P1 ... PN
of the
grammar, the constructor for this rule starts with the name of the
non terminal A and continues with the names of producers Pi
appearing in the right-hand-side of the production rule. We do not
need types for operators and reserved words.
These concrete syntax trees are actually richer than the
production trees defined by the grammar. Indeed, they also embed
concrete syntax trees for WORDs while the grammar sees WORDs are
mere tokens. For instance, echo `cat bar`
is interpreted by the
grammar as a simple command with two WORDs echo
and `cat bar`
.
Morbig does not stop its work here: it also parses `cat bar` and
the resulting concrete syntax tree is attached to the WORD
`cat bar`
. See the type definition for word
below for more
details.
The PPX syntax extension package "visitors", written by François
Pottier, is used to macro-generate many traversal functions over
this concrete syntax tree. Note that we expose the .ml file of
this module because the types generated by visitors
are too
complex to be displayed.
type
position = {
|
start_p : |
|
end_p : |
}
typelexing_position =
Stdlib.Lexing.position
= {
|
pos_fname : |
|
pos_lnum : |
|
pos_bol : |
|
pos_cnum : |
}
type 'a
located = {
|
value : |
|
position : |
}
type
program =
| |
Program_LineBreak_CompleteCommands_LineBreak of |
| |
Program_LineBreak of |
type
complete_commands =
| |
CompleteCommands_CompleteCommands_NewlineList_CompleteCommand of |
| |
CompleteCommands_CompleteCommand of |
type
complete_command =
| |
CompleteCommand_CList_SeparatorOp of |
| |
CompleteCommand_CList of |
type
clist =
| |
CList_CList_SeparatorOp_AndOr of |
| |
CList_AndOr of |
type
and_or =
| |
AndOr_Pipeline of |
| |
AndOr_AndOr_AndIf_LineBreak_Pipeline of |
| |
AndOr_AndOr_OrIf_LineBreak_Pipeline of |
type
pipeline =
| |
Pipeline_PipeSequence of |
| |
Pipeline_Bang_PipeSequence of |
type
pipe_sequence =
| |
PipeSequence_Command of |
| |
PipeSequence_PipeSequence_Pipe_LineBreak_Command of |
type
command =
| |
Command_SimpleCommand of |
| |
Command_CompoundCommand of |
| |
Command_CompoundCommand_RedirectList of |
| |
Command_FunctionDefinition of |
type
compound_command =
| |
CompoundCommand_BraceGroup of |
| |
CompoundCommand_Subshell of |
| |
CompoundCommand_ForClause of |
| |
CompoundCommand_CaseClause of |
| |
CompoundCommand_IfClause of |
| |
CompoundCommand_WhileClause of |
| |
CompoundCommand_UntilClause of |
type
subshell =
| |
Subshell_Lparen_CompoundList_Rparen of |
type
compound_list =
| |
CompoundList_LineBreak_Term of |
| |
CompoundList_LineBreak_Term_Separator of |
type
term =
| |
Term_Term_Separator_AndOr of |
| |
Term_AndOr of |
type
for_clause =
| |
ForClause_For_Name_DoGroup of |
| |
ForClause_For_Name_SequentialSep_DoGroup of |
| |
ForClause_For_Name_LineBreak_In_SequentialSep_DoGroup of |
| |
ForClause_For_Name_LineBreak_In_WordList_SequentialSep_DoGroup of |
type
wordlist =
| |
WordList_WordList_Word of |
| |
WordList_Word of |
type
case_clause =
| |
CaseClause_Case_Word_LineBreak_In_LineBreak_CaseList_Esac of |
| |
CaseClause_Case_Word_LineBreak_In_LineBreak_CaseListNS_Esac of |
| |
CaseClause_Case_Word_LineBreak_In_LineBreak_Esac of |
type
case_list_ns =
| |
CaseListNS_CaseList_CaseItemNS of |
| |
CaseListNS_CaseItemNS of |
type
case_list =
| |
CaseList_CaseList_CaseItem of |
| |
CaseList_CaseItem of |
type
case_item_ns =
| |
CaseItemNS_Pattern_Rparen_LineBreak of |
| |
CaseItemNS_Pattern_Rparen_CompoundList of |
| |
CaseItemNS_Lparen_Pattern_Rparen_LineBreak of |
| |
CaseItemNS_Lparen_Pattern_Rparen_CompoundList of |
type
case_item =
| |
CaseItem_Pattern_Rparen_LineBreak_Dsemi_LineBreak of |
| |
CaseItem_Pattern_Rparen_CompoundList_Dsemi_LineBreak of |
| |
CaseItem_Lparen_Pattern_Rparen_LineBreak_Dsemi_LineBreak of |
| |
CaseItem_Lparen_Pattern_Rparen_CompoundList_Dsemi_LineBreak of |
type
pattern =
| |
Pattern_Word of |
| |
Pattern_Pattern_Pipe_Word of |
type
if_clause =
| |
IfClause_If_CompoundList_Then_CompoundList_ElsePart_Fi of |
| |
IfClause_If_CompoundList_Then_CompoundList_Fi of |
type
else_part =
| |
ElsePart_Elif_CompoundList_Then_CompoundList of |
| |
ElsePart_Elif_CompoundList_Then_CompoundList_ElsePart of |
| |
ElsePart_Else_CompoundList of |
type
while_clause =
| |
WhileClause_While_CompoundList_DoGroup of |
type
until_clause =
| |
UntilClause_Until_CompoundList_DoGroup of |
type
function_definition =
| |
FunctionDefinition_Fname_Lparen_Rparen_LineBreak_FunctionBody of |
type
function_body =
| |
FunctionBody_CompoundCommand of |
| |
FunctionBody_CompoundCommand_RedirectList of |
type
fname =
| |
Fname_Name of |
type
brace_group =
| |
BraceGroup_LBrace_CompoundList_RBrace of |
type
do_group =
| |
DoGroup_Do_CompoundList_Done of |
type
simple_command =
| |
SimpleCommand_CmdPrefix_CmdWord_CmdSuffix of |
| |
SimpleCommand_CmdPrefix_CmdWord of |
| |
SimpleCommand_CmdPrefix of |
| |
SimpleCommand_CmdName_CmdSuffix of |
| |
SimpleCommand_CmdName of |
type
cmd_name =
| |
CmdName_Word of |
type
cmd_word =
| |
CmdWord_Word of |
type
cmd_prefix =
| |
CmdPrefix_IoRedirect of |
| |
CmdPrefix_CmdPrefix_IoRedirect of |
| |
CmdPrefix_AssignmentWord of |
| |
CmdPrefix_CmdPrefix_AssignmentWord of |
type
cmd_suffix =
| |
CmdSuffix_IoRedirect of |
| |
CmdSuffix_CmdSuffix_IoRedirect of |
| |
CmdSuffix_Word of |
| |
CmdSuffix_CmdSuffix_Word of |
type
redirect_list =
| |
RedirectList_IoRedirect of |
| |
RedirectList_RedirectList_IoRedirect of |
type
io_redirect =
| |
IoRedirect_IoFile of |
| |
IoRedirect_IoNumber_IoFile of |
| |
IoRedirect_IoHere of |
| |
IoRedirect_IoNumber_IoHere of |
type
io_file =
| |
IoFile_Less_FileName of |
| |
IoFile_LessAnd_FileName of |
| |
IoFile_Great_FileName of |
| |
IoFile_GreatAnd_FileName of |
| |
IoFile_DGreat_FileName of |
| |
IoFile_LessGreat_FileName of |
| |
IoFile_Clobber_FileName of |
type
filename =
| |
Filename_Word of |
type
io_here =
| |
IoHere_DLess_HereEnd of |
| |
IoHere_DLessDash_HereEnd of |
The two IoHere constructors have two arguments. The second argument is the word holding the contents of the here document, which does not figure in the grammar.
type
here_end =
| |
HereEnd_Word of |
type
newline_list =
| |
NewLineList_NewLine |
| |
NewLineList_NewLineList_NewLine of |
type
linebreak =
| |
LineBreak_NewLineList of |
| |
LineBreak_Empty |
type
separator_op =
| |
SeparatorOp_Uppersand |
| |
SeparatorOp_Semicolon |
type
separator =
| |
Separator_SeparatorOp_LineBreak of |
| |
Separator_NewLineList of |
type
sequential_sep =
| |
SequentialSep_Semicolon_LineBreak of |
| |
SequentialSep_NewLineList of |
type
word =
| |
Word of |
typeword_cst =
word_component list
type
word_component =
| |
WordSubshell of |
| |
WordName of |
| |
WordAssignmentWord of |
| |
WordDoubleQuoted of |
| |
WordSingleQuoted of |
| |
WordTildePrefix of |
| |
WordLiteral of |
| |
WordVariable of |
| |
WordGlobAll |
| |
WordGlobAny |
| |
WordReBracketExpression of |
| |
WordEmpty |
type
bracket_expression =
| |
BracketExpression_LBRACKET_MatchingList_RBRACKET of |
| |
BracketExpression_LBRACKET_NonMatchingList_RBRACKET of |
type
matching_list =
| |
MatchingList_BracketList of |
type
nonmatching_list =
| |
NonMatchingList_BracketList of |
type
bracket_list =
| |
BracketList_FollowList of |
| |
BracketList_FollowList_MINUS of |
type
follow_list =
| |
FollowList_ExpressionTerm of |
| |
FollowList_FollowList_ExpressionTerm of |
type
expression_term =
| |
ExpressionTerm_SingleExpression of |
| |
ExpressionTerm_RangeExpression of |
type
single_expression =
| |
SingleExpression_EndRange of |
| |
SingleExpression_CharacterClass of |
| |
SingleExpression_EquivalenceClass of |
type
range_expression =
| |
RangeExpression_StartRange_EndRange of |
| |
RangeExpression_StartRange_MINUS of |
type
start_range =
| |
StartRange_EndRange_MINUS of |
type
end_range =
| |
EndRange_COLLELEMSINGLE of |
| |
EndRangeCollatingSymbol of |
type
collating_symbol =
| |
CollatingSymbol_OpenDot_COLLELEMSINGLE_DotClose of |
| |
CollatingSymbol_OpenDot_COLLELEMMULTI_DotClose of |
| |
CollatingSymbol_OpenDot_METACHAR_DotClose of |
type
equivalence_class =
| |
EquivalenceClass_OpenEqual_COLLELEMSINGLE_EqualClose of |
| |
EquivalenceClass_OpenEqual_COLLELEMMULTI_EqualClose of |
type
character_class =
| |
CharacterClass_OpenColon_CLASSNAME_ColonClose of |
type
class_name =
| |
ClassName of |
type
character_range =
| |
Range of |
type
variable =
| |
VariableAtom of |
type
variable_attribute =
| |
NoAttribute |
| |
ParameterLength |
| |
UseDefaultValues of |
| |
AssignDefaultValues of |
| |
IndicateErrorifNullorUnset of |
| |
UseAlternativeValue of |
| |
RemoveSmallestSuffixPattern of |
| |
RemoveLargestSuffixPattern of |
| |
RemoveSmallestPrefixPattern of |
| |
RemoveLargestPrefixPattern of |
type
subshell_kind =
| |
SubShellKindBackQuote |
| |
SubShellKindParentheses |
type
name =
| |
Name of |
typeassignment_word =
name * word
type
io_number =
| |
IONumber of |
typeprogram' =
program located
typecomplete_commands' =
complete_commands located
typecomplete_command' =
complete_command located
typeclist' =
clist located
typeand_or' =
and_or located
typepipeline' =
pipeline located
typepipe_sequence' =
pipe_sequence located
typecommand' =
command located
typecompound_command' =
compound_command located
typesubshell' =
subshell located
typecompound_list' =
compound_list located
typeterm' =
term located
typefor_clause' =
for_clause located
typewordlist' =
wordlist located
typecase_clause' =
case_clause located
typecase_list_ns' =
case_list_ns located
typecase_list' =
case_list located
typecase_item_ns' =
case_item_ns located
typecase_item' =
case_item located
typepattern' =
pattern located
typeif_clause' =
if_clause located
typeelse_part' =
else_part located
typewhile_clause' =
while_clause located
typeuntil_clause' =
until_clause located
typefunction_definition' =
function_definition located
typefunction_body' =
function_body located
typefname' =
fname located
typebrace_group' =
brace_group located
typedo_group' =
do_group located
typesimple_command' =
simple_command located
typecmd_name' =
cmd_name located
typecmd_word' =
cmd_word located
typecmd_prefix' =
cmd_prefix located
typecmd_suffix' =
cmd_suffix located
typeredirect_list' =
redirect_list located
typeio_redirect' =
io_redirect located
typeio_file' =
io_file located
typefilename' =
filename located
typeio_here' =
io_here located
typehere_end' =
here_end located
typenewline_list' =
newline_list located
typelinebreak' =
linebreak located
typeseparator_op' =
separator_op located
typeseparator' =
separator located
typesequential_sep' =
sequential_sep located
typeword' =
word located
typename' =
name located
typeassignment_word' =
assignment_word located