package morbig

  1. Overview
  2. Docs

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 = {
  1. start_p : lexing_position;
  2. end_p : lexing_position;
}
and lexing_position = Lexing.position = {
  1. pos_fname : string;
  2. pos_lnum : int;
  3. pos_bol : int;
  4. pos_cnum : int;
}
and 'a located = {
  1. value : 'a;
  2. position : position;
}
type program =
  1. | Program_LineBreak_CompleteCommands_LineBreak of linebreak' * complete_commands' * linebreak'
  2. | Program_LineBreak of linebreak'
and complete_commands =
  1. | CompleteCommands_CompleteCommands_NewlineList_CompleteCommand of complete_commands' * newline_list' * complete_command'
  2. | CompleteCommands_CompleteCommand of complete_command'
and complete_command =
  1. | CompleteCommand_CList_SeparatorOp of clist' * separator_op'
  2. | CompleteCommand_CList of clist'
and clist =
  1. | CList_CList_SeparatorOp_AndOr of clist' * separator_op' * and_or'
  2. | CList_AndOr of and_or'
and and_or =
  1. | AndOr_Pipeline of pipeline'
  2. | AndOr_AndOr_AndIf_LineBreak_Pipeline of and_or' * linebreak' * pipeline'
  3. | AndOr_AndOr_OrIf_LineBreak_Pipeline of and_or' * linebreak' * pipeline'
and pipeline =
  1. | Pipeline_PipeSequence of pipe_sequence'
  2. | Pipeline_Bang_PipeSequence of pipe_sequence'
and pipe_sequence =
  1. | PipeSequence_Command of command'
  2. | PipeSequence_PipeSequence_Pipe_LineBreak_Command of pipe_sequence' * linebreak' * command'
and command =
  1. | Command_SimpleCommand of simple_command'
  2. | Command_CompoundCommand of compound_command'
  3. | Command_CompoundCommand_RedirectList of compound_command' * redirect_list'
  4. | Command_FunctionDefinition of function_definition'
and compound_command =
  1. | CompoundCommand_BraceGroup of brace_group'
  2. | CompoundCommand_Subshell of subshell'
  3. | CompoundCommand_ForClause of for_clause'
  4. | CompoundCommand_CaseClause of case_clause'
  5. | CompoundCommand_IfClause of if_clause'
  6. | CompoundCommand_WhileClause of while_clause'
  7. | CompoundCommand_UntilClause of until_clause'
and subshell =
  1. | Subshell_Lparen_CompoundList_Rparen of compound_list'
and compound_list =
  1. | CompoundList_LineBreak_Term of linebreak' * term'
  2. | CompoundList_LineBreak_Term_Separator of linebreak' * term' * separator'
and term =
  1. | Term_Term_Separator_AndOr of term' * separator' * and_or'
  2. | Term_AndOr of and_or'
and for_clause =
  1. | ForClause_For_Name_DoGroup of name' * do_group'
  2. | ForClause_For_Name_SequentialSep_DoGroup of name' * sequential_sep' * do_group'
  3. | ForClause_For_Name_LineBreak_In_SequentialSep_DoGroup of name' * linebreak' * sequential_sep' * do_group'
  4. | ForClause_For_Name_LineBreak_In_WordList_SequentialSep_DoGroup of name' * linebreak' * wordlist' * sequential_sep' * do_group'
and wordlist =
  1. | WordList_WordList_Word of wordlist' * word'
  2. | WordList_Word of word'
and case_clause =
  1. | CaseClause_Case_Word_LineBreak_In_LineBreak_CaseList_Esac of word' * linebreak' * linebreak' * case_list'
  2. | CaseClause_Case_Word_LineBreak_In_LineBreak_CaseListNS_Esac of word' * linebreak' * linebreak' * case_list_ns'
  3. | CaseClause_Case_Word_LineBreak_In_LineBreak_Esac of word' * linebreak' * linebreak'
and case_list_ns =
  1. | CaseListNS_CaseList_CaseItemNS of case_list' * case_item_ns'
  2. | CaseListNS_CaseItemNS of case_item_ns'
and case_list =
  1. | CaseList_CaseList_CaseItem of case_list' * case_item'
  2. | CaseList_CaseItem of case_item'
and case_item_ns =
  1. | CaseItemNS_Pattern_Rparen_LineBreak of pattern' * linebreak'
  2. | CaseItemNS_Pattern_Rparen_CompoundList of pattern' * compound_list'
  3. | CaseItemNS_Lparen_Pattern_Rparen_LineBreak of pattern' * linebreak'
  4. | CaseItemNS_Lparen_Pattern_Rparen_CompoundList of pattern' * compound_list'
and case_item =
  1. | CaseItem_Pattern_Rparen_LineBreak_Dsemi_LineBreak of pattern' * linebreak' * linebreak'
  2. | CaseItem_Pattern_Rparen_CompoundList_Dsemi_LineBreak of pattern' * compound_list' * linebreak'
  3. | CaseItem_Lparen_Pattern_Rparen_LineBreak_Dsemi_LineBreak of pattern' * linebreak' * linebreak'
  4. | CaseItem_Lparen_Pattern_Rparen_CompoundList_Dsemi_LineBreak of pattern' * compound_list' * linebreak'
and pattern =
  1. | Pattern_Word of word'
  2. | Pattern_Pattern_Pipe_Word of pattern' * word'
and if_clause =
  1. | IfClause_If_CompoundList_Then_CompoundList_ElsePart_Fi of compound_list' * compound_list' * else_part'
  2. | IfClause_If_CompoundList_Then_CompoundList_Fi of compound_list' * compound_list'
and else_part =
  1. | ElsePart_Elif_CompoundList_Then_CompoundList of compound_list' * compound_list'
  2. | ElsePart_Elif_CompoundList_Then_CompoundList_ElsePart of compound_list' * compound_list' * else_part'
  3. | ElsePart_Else_CompoundList of compound_list'
and while_clause =
  1. | WhileClause_While_CompoundList_DoGroup of compound_list' * do_group'
and until_clause =
  1. | UntilClause_Until_CompoundList_DoGroup of compound_list' * do_group'
and function_definition =
  1. | FunctionDefinition_Fname_Lparen_Rparen_LineBreak_FunctionBody of fname' * linebreak' * function_body'
and function_body =
  1. | FunctionBody_CompoundCommand of compound_command'
  2. | FunctionBody_CompoundCommand_RedirectList of compound_command' * redirect_list'
and fname =
  1. | Fname_Name of name
and brace_group =
  1. | BraceGroup_LBrace_CompoundList_RBrace of compound_list'
and do_group =
  1. | DoGroup_Do_CompoundList_Done of compound_list'
and simple_command =
  1. | SimpleCommand_CmdPrefix_CmdWord_CmdSuffix of cmd_prefix' * cmd_word' * cmd_suffix'
  2. | SimpleCommand_CmdPrefix_CmdWord of cmd_prefix' * cmd_word'
  3. | SimpleCommand_CmdPrefix of cmd_prefix'
  4. | SimpleCommand_CmdName_CmdSuffix of cmd_name' * cmd_suffix'
  5. | SimpleCommand_CmdName of cmd_name'
and cmd_name =
  1. | CmdName_Word of word'
and cmd_word =
  1. | CmdWord_Word of word'
and cmd_prefix =
  1. | CmdPrefix_IoRedirect of io_redirect'
  2. | CmdPrefix_CmdPrefix_IoRedirect of cmd_prefix' * io_redirect'
  3. | CmdPrefix_AssignmentWord of assignment_word'
  4. | CmdPrefix_CmdPrefix_AssignmentWord of cmd_prefix' * assignment_word'
and cmd_suffix =
  1. | CmdSuffix_IoRedirect of io_redirect'
  2. | CmdSuffix_CmdSuffix_IoRedirect of cmd_suffix' * io_redirect'
  3. | CmdSuffix_Word of word'
  4. | CmdSuffix_CmdSuffix_Word of cmd_suffix' * word'
and redirect_list =
  1. | RedirectList_IoRedirect of io_redirect'
  2. | RedirectList_RedirectList_IoRedirect of redirect_list' * io_redirect'
and io_redirect =
  1. | IoRedirect_IoFile of io_file'
  2. | IoRedirect_IoNumber_IoFile of io_number * io_file'
  3. | IoRedirect_IoHere of io_here'
  4. | IoRedirect_IoNumber_IoHere of io_number * io_here'
and io_file =
  1. | IoFile_Less_FileName of filename'
  2. | IoFile_LessAnd_FileName of filename'
  3. | IoFile_Great_FileName of filename'
  4. | IoFile_GreatAnd_FileName of filename'
  5. | IoFile_DGreat_FileName of filename'
  6. | IoFile_LessGreat_FileName of filename'
  7. | IoFile_Clobber_FileName of filename'
and filename =
  1. | Filename_Word of word'
and io_here =
  1. | IoHere_DLess_HereEnd of here_end' * word' ref
  2. | IoHere_DLessDash_HereEnd of here_end' * word' ref

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.

and here_end =
  1. | HereEnd_Word of word'
and newline_list =
  1. | NewLineList_NewLine
  2. | NewLineList_NewLineList_NewLine of newline_list'
and linebreak =
  1. | LineBreak_NewLineList of newline_list'
  2. | LineBreak_Empty
and separator_op =
  1. | SeparatorOp_Uppersand
  2. | SeparatorOp_Semicolon
and separator =
  1. | Separator_SeparatorOp_LineBreak of separator_op' * linebreak'
  2. | Separator_NewLineList of newline_list'
and sequential_sep =
  1. | SequentialSep_Semicolon_LineBreak of linebreak'
  2. | SequentialSep_NewLineList of newline_list'
and word =
  1. | Word of string * word_cst
and word_cst = word_component list
and word_component =
  1. | WordSubshell of subshell_kind * program located
  2. | WordName of string
  3. | WordAssignmentWord of assignment_word
  4. | WordDoubleQuoted of word
  5. | WordSingleQuoted of word
  6. | WordTildePrefix of string
  7. | WordLiteral of string
  8. | WordVariable of variable
  9. | WordGlobAll
  10. | WordGlobAny
  11. | WordReBracketExpression of bracket_expression
  12. | WordEmpty
and bracket_expression =
  1. | BracketExpression_LBRACKET_MatchingList_RBRACKET of matching_list
  2. | BracketExpression_LBRACKET_NonMatchingList_RBRACKET of nonmatching_list
and matching_list =
  1. | MatchingList_BracketList of bracket_list
and nonmatching_list =
  1. | NonMatchingList_BracketList of bracket_list
and bracket_list =
  1. | BracketList_FollowList of follow_list
  2. | BracketList_FollowList_MINUS of follow_list
and follow_list =
  1. | FollowList_ExpressionTerm of expression_term
  2. | FollowList_FollowList_ExpressionTerm of follow_list * expression_term
and expression_term =
  1. | ExpressionTerm_SingleExpression of single_expression
  2. | ExpressionTerm_RangeExpression of range_expression
and single_expression =
  1. | SingleExpression_EndRange of end_range
  2. | SingleExpression_CharacterClass of character_class
  3. | SingleExpression_EquivalenceClass of equivalence_class
and range_expression =
  1. | RangeExpression_StartRange_EndRange of start_range * end_range
  2. | RangeExpression_StartRange_MINUS of start_range
and start_range =
  1. | StartRange_EndRange_MINUS of end_range
and end_range =
  1. | EndRange_COLLELEMSINGLE of char
  2. | EndRangeCollatingSymbol of collating_symbol
and collating_symbol =
  1. | CollatingSymbol_OpenDot_COLLELEMSINGLE_DotClose of char
  2. | CollatingSymbol_OpenDot_COLLELEMMULTI_DotClose of string
  3. | CollatingSymbol_OpenDot_METACHAR_DotClose of char
and equivalence_class =
  1. | EquivalenceClass_OpenEqual_COLLELEMSINGLE_EqualClose of char
  2. | EquivalenceClass_OpenEqual_COLLELEMMULTI_EqualClose of string
and character_class =
  1. | CharacterClass_OpenColon_CLASSNAME_ColonClose of class_name
and class_name =
  1. | ClassName of string
and character_range =
  1. | Range of char list
and variable =
  1. | VariableAtom of string * variable_attribute
and variable_attribute =
  1. | NoAttribute
  2. | ParameterLength
  3. | UseDefaultValues of string * word
  4. | AssignDefaultValues of string * word
  5. | IndicateErrorifNullorUnset of string * word
  6. | UseAlternativeValue of string * word
  7. | RemoveSmallestSuffixPattern of word
  8. | RemoveLargestSuffixPattern of word
  9. | RemoveSmallestPrefixPattern of word
  10. | RemoveLargestPrefixPattern of word
and subshell_kind =
  1. | SubShellKindBackQuote
  2. | SubShellKindParentheses
and name =
  1. | Name of string
and assignment_word = name * word
and io_number =
  1. | IONumber of string
and program' = program located
and complete_commands' = complete_commands located
and complete_command' = complete_command located
and clist' = clist located
and and_or' = and_or located
and pipeline' = pipeline located
and pipe_sequence' = pipe_sequence located
and command' = command located
and compound_command' = compound_command located
and subshell' = subshell located
and compound_list' = compound_list located
and term' = term located
and for_clause' = for_clause located
and wordlist' = wordlist located
and case_clause' = case_clause located
and case_list_ns' = case_list_ns located
and case_list' = case_list located
and case_item_ns' = case_item_ns located
and case_item' = case_item located
and pattern' = pattern located
and if_clause' = if_clause located
and else_part' = else_part located
and while_clause' = while_clause located
and until_clause' = until_clause located
and function_definition' = function_definition located
and function_body' = function_body located
and fname' = fname located
and brace_group' = brace_group located
and do_group' = do_group located
and simple_command' = simple_command located
and cmd_name' = cmd_name located
and cmd_word' = cmd_word located
and cmd_prefix' = cmd_prefix located
and cmd_suffix' = cmd_suffix located
and redirect_list' = redirect_list located
and io_redirect' = io_redirect located
and io_file' = io_file located
and filename' = filename located
and io_here' = io_here located
and here_end' = here_end located
and newline_list' = newline_list located
and linebreak' = linebreak located
and separator_op' = separator_op located
and separator' = separator located
and sequential_sep' = sequential_sep located
and word' = word located
and name' = name located
and assignment_word' = assignment_word located
OCaml

Innovation. Community. Security.