morbig

A trustworthy parser for POSIX shell
Module Morbig . CST
type position = {
start_p : lexing_position;
end_p : lexing_position;
}

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.

and lexing_position = Lexing.position = {
pos_fname : string;
pos_lnum : int;
pos_bol : int;
pos_cnum : int;
}
and 'a located = {
value : 'a;
position : position;
}
val position_to_yojson : position -> Yojson.Safe.t
val lexing_position_to_yojson : lexing_position -> Yojson.Safe.t
val located_to_yojson : 'a. ( 'a -> Yojson.Safe.t ) -> 'a located -> Yojson.Safe.t
class virtual +'a located_iter : object ... end
class virtual +'a located_map : object ... end
class virtual +'a located_reduce : object ... end
class virtual +'a located_mapreduce : object ... end
class virtual +'a located_iter2 : object ... end
class virtual +'a located_map2 : object ... end
class virtual +'a located_reduce2 : object ... end
type program =
| Program_LineBreak_CompleteCommands_LineBreak of linebreak' * complete_commands' * linebreak'
| Program_LineBreak of linebreak'
and complete_commands =
| CompleteCommands_CompleteCommands_NewlineList_CompleteCommand of complete_commands' * newline_list' * complete_command'
| CompleteCommands_CompleteCommand of complete_command'
and complete_command =
| CompleteCommand_CList_SeparatorOp of clist' * separator_op'
| CompleteCommand_CList of clist'
and clist =
| CList_CList_SeparatorOp_AndOr of clist' * separator_op' * and_or'
| CList_AndOr of and_or'
and and_or =
| AndOr_Pipeline of pipeline'
| AndOr_AndOr_AndIf_LineBreak_Pipeline of and_or' * linebreak' * pipeline'
| AndOr_AndOr_OrIf_LineBreak_Pipeline of and_or' * linebreak' * pipeline'
and pipeline =
| Pipeline_PipeSequence of pipe_sequence'
| Pipeline_Bang_PipeSequence of pipe_sequence'
and pipe_sequence =
| PipeSequence_Command of command'
| PipeSequence_PipeSequence_Pipe_LineBreak_Command of pipe_sequence' * linebreak' * command'
and command =
| Command_SimpleCommand of simple_command'
| Command_CompoundCommand of compound_command'
| Command_CompoundCommand_RedirectList of compound_command' * redirect_list'
| Command_FunctionDefinition of function_definition'
and compound_command =
| CompoundCommand_BraceGroup of brace_group'
| CompoundCommand_Subshell of subshell'
| CompoundCommand_ForClause of for_clause'
| CompoundCommand_CaseClause of case_clause'
| CompoundCommand_IfClause of if_clause'
| CompoundCommand_WhileClause of while_clause'
| CompoundCommand_UntilClause of until_clause'
and subshell =
| Subshell_Lparen_CompoundList_Rparen of compound_list'
and compound_list =
| CompoundList_LineBreak_Term of linebreak' * term'
| CompoundList_LineBreak_Term_Separator of linebreak' * term' * separator'
and term =
| Term_Term_Separator_AndOr of term' * separator' * and_or'
| Term_AndOr of and_or'
and for_clause =
| ForClause_For_Name_DoGroup of name' * do_group'
| ForClause_For_Name_SequentialSep_DoGroup of name' * sequential_sep' * do_group'
| ForClause_For_Name_LineBreak_In_SequentialSep_DoGroup of name' * linebreak' * sequential_sep' * do_group'
| ForClause_For_Name_LineBreak_In_WordList_SequentialSep_DoGroup of name' * linebreak' * wordlist' * sequential_sep' * do_group'
and wordlist =
| WordList_WordList_Word of wordlist' * word'
| WordList_Word of word'
and case_clause =
| CaseClause_Case_Word_LineBreak_In_LineBreak_CaseList_Esac of word' * linebreak' * linebreak' * case_list'
| CaseClause_Case_Word_LineBreak_In_LineBreak_CaseListNS_Esac of word' * linebreak' * linebreak' * case_list_ns'
| CaseClause_Case_Word_LineBreak_In_LineBreak_Esac of word' * linebreak' * linebreak'
and case_list_ns =
| CaseListNS_CaseList_CaseItemNS of case_list' * case_item_ns'
| CaseListNS_CaseItemNS of case_item_ns'
and case_list =
| CaseList_CaseList_CaseItem of case_list' * case_item'
| CaseList_CaseItem of case_item'
and case_item_ns =
| CaseItemNS_Pattern_Rparen_LineBreak of pattern' * linebreak'
| CaseItemNS_Pattern_Rparen_CompoundList of pattern' * compound_list'
| CaseItemNS_Lparen_Pattern_Rparen_LineBreak of pattern' * linebreak'
| CaseItemNS_Lparen_Pattern_Rparen_CompoundList of pattern' * compound_list'
and case_item =
| CaseItem_Pattern_Rparen_LineBreak_Dsemi_LineBreak of pattern' * linebreak' * linebreak'
| CaseItem_Pattern_Rparen_CompoundList_Dsemi_LineBreak of pattern' * compound_list' * linebreak'
| CaseItem_Lparen_Pattern_Rparen_LineBreak_Dsemi_LineBreak of pattern' * linebreak' * linebreak'
| CaseItem_Lparen_Pattern_Rparen_CompoundList_Dsemi_LineBreak of pattern' * compound_list' * linebreak'
and pattern =
| Pattern_Word of word'
| Pattern_Pattern_Pipe_Word of pattern' * word'
and if_clause =
| IfClause_If_CompoundList_Then_CompoundList_ElsePart_Fi of compound_list' * compound_list' * else_part'
| IfClause_If_CompoundList_Then_CompoundList_Fi of compound_list' * compound_list'
and else_part =
| ElsePart_Elif_CompoundList_Then_CompoundList of compound_list' * compound_list'
| ElsePart_Elif_CompoundList_Then_CompoundList_ElsePart of compound_list' * compound_list' * else_part'
| ElsePart_Else_CompoundList of compound_list'
and while_clause =
| WhileClause_While_CompoundList_DoGroup of compound_list' * do_group'
and until_clause =
| UntilClause_Until_CompoundList_DoGroup of compound_list' * do_group'
and function_definition =
| FunctionDefinition_Fname_Lparen_Rparen_LineBreak_FunctionBody of fname' * linebreak' * function_body'
and function_body =
| FunctionBody_CompoundCommand of compound_command'
| FunctionBody_CompoundCommand_RedirectList of compound_command' * redirect_list'
and fname =
| Fname_Name of name
and brace_group =
| BraceGroup_LBrace_CompoundList_RBrace of compound_list'
and do_group =
| DoGroup_Do_CompoundList_Done of compound_list'
and simple_command =
| SimpleCommand_CmdPrefix_CmdWord_CmdSuffix of cmd_prefix' * cmd_word' * cmd_suffix'
| SimpleCommand_CmdPrefix_CmdWord of cmd_prefix' * cmd_word'
| SimpleCommand_CmdPrefix of cmd_prefix'
| SimpleCommand_CmdName_CmdSuffix of cmd_name' * cmd_suffix'
| SimpleCommand_CmdName of cmd_name'
and cmd_name =
| CmdName_Word of word'
and cmd_word =
| CmdWord_Word of word'
and cmd_prefix =
| CmdPrefix_IoRedirect of io_redirect'
| CmdPrefix_CmdPrefix_IoRedirect of cmd_prefix' * io_redirect'
| CmdPrefix_AssignmentWord of assignment_word'
| CmdPrefix_CmdPrefix_AssignmentWord of cmd_prefix' * assignment_word'
and cmd_suffix =
| CmdSuffix_IoRedirect of io_redirect'
| CmdSuffix_CmdSuffix_IoRedirect of cmd_suffix' * io_redirect'
| CmdSuffix_Word of word'
| CmdSuffix_CmdSuffix_Word of cmd_suffix' * word'
and redirect_list =
| RedirectList_IoRedirect of io_redirect'
| RedirectList_RedirectList_IoRedirect of redirect_list' * io_redirect'
and io_redirect =
| IoRedirect_IoFile of io_file'
| IoRedirect_IoNumber_IoFile of io_number * io_file'
| IoRedirect_IoHere of io_here'
| IoRedirect_IoNumber_IoHere of io_number * io_here'
and io_file =
| IoFile_Less_FileName of filename'
| IoFile_LessAnd_FileName of filename'
| IoFile_Great_FileName of filename'
| IoFile_GreatAnd_FileName of filename'
| IoFile_DGreat_FileName of filename'
| IoFile_LessGreat_FileName of filename'
| IoFile_Clobber_FileName of filename'
and filename =
| Filename_Word of word'
and io_here =
| IoHere_DLess_HereEnd of here_end' * word' ref
| 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 =
| HereEnd_Word of word'
and newline_list =
| NewLineList_NewLine
| NewLineList_NewLineList_NewLine of newline_list'
and linebreak =
| LineBreak_NewLineList of newline_list'
| LineBreak_Empty
and separator_op =
| SeparatorOp_Uppersand
| SeparatorOp_Semicolon
and separator =
| Separator_SeparatorOp_LineBreak of separator_op' * linebreak'
| Separator_NewLineList of newline_list'
and sequential_sep =
| SequentialSep_Semicolon_LineBreak of linebreak'
| SequentialSep_NewLineList of newline_list'
and word =
| Word of string * word_cst
and word_cst = word_component list
and word_component =
| WordSubshell of subshell_kind * program located
| WordName of string
| WordAssignmentWord of assignment_word
| WordDoubleQuoted of word
| WordSingleQuoted of word
| WordLiteral of string
| WordVariable of variable
| WordGlobAll
| WordGlobAny
| WordReBracketExpression of bracket_expression
| WordEmpty
and bracket_expression =
| BracketExpression_LBRACKET_MatchingList_RBRACKET of matching_list
| BracketExpression_LBRACKET_NonMatchingList_RBRACKET of nonmatching_list
and matching_list =
| MatchingList_BracketList of bracket_list
and nonmatching_list =
| NonMatchingList_BracketList of bracket_list
and bracket_list =
| BracketList_FollowList of follow_list
| BracketList_FollowList_MINUS of follow_list
and follow_list =
| FollowList_ExpressionTerm of expression_term
| FollowList_FollowList_ExpressionTerm of follow_list * expression_term
and expression_term =
| ExpressionTerm_SingleExpression of single_expression
| ExpressionTerm_RangeExpression of range_expression
and single_expression =
| SingleExpression_EndRange of end_range
| SingleExpression_CharacterClass of character_class
| SingleExpression_EquivalenceClass of equivalence_class
and range_expression =
| RangeExpression_StartRange_EndRange of start_range * end_range
| RangeExpression_StartRange_MINUS of start_range
and start_range =
| StartRange_EndRange_MINUS of end_range
and end_range =
| EndRange_COLLELEMSINGLE of char
| EndRangeCollatingSymbol of collating_symbol
and collating_symbol =
| CollatingSymbol_OpenDot_COLLELEMSINGLE_DotClose of char
| CollatingSymbol_OpenDot_COLLELEMMULTI_DotClose of string
| CollatingSymbol_OpenDot_METACHAR_DotClose of char
and equivalence_class =
| EquivalenceClass_OpenEqual_COLLELEMSINGLE_EqualClose of char
| EquivalenceClass_OpenEqual_COLLELEMMULTI_EqualClose of string
and character_class =
| CharacterClass_OpenColon_CLASSNAME_ColonClose of class_name
and class_name =
| ClassName of string
and character_range =
| Range of char list
and variable =
| VariableAtom of string * variable_attribute
and variable_attribute =
| NoAttribute
| ParameterLength of word
| UseDefaultValues of string * word
| AssignDefaultValues of string * word
| IndicateErrorifNullorUnset of string * word
| UseAlternativeValue of string * word
| RemoveSmallestSuffixPattern of word
| RemoveLargestSuffixPattern of word
| RemoveSmallestPrefixPattern of word
| RemoveLargestPrefixPattern of word
and subshell_kind =
| SubShellKindBackQuote
| SubShellKindParentheses
and name =
| Name of string
and assignment_word = name * word
and io_number =
| 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
val program_to_yojson : program -> Yojson.Safe.t
val complete_commands_to_yojson : complete_commands -> Yojson.Safe.t
val complete_command_to_yojson : complete_command -> Yojson.Safe.t
val clist_to_yojson : clist -> Yojson.Safe.t
val and_or_to_yojson : and_or -> Yojson.Safe.t
val pipeline_to_yojson : pipeline -> Yojson.Safe.t
val pipe_sequence_to_yojson : pipe_sequence -> Yojson.Safe.t
val command_to_yojson : command -> Yojson.Safe.t
val compound_command_to_yojson : compound_command -> Yojson.Safe.t
val subshell_to_yojson : subshell -> Yojson.Safe.t
val compound_list_to_yojson : compound_list -> Yojson.Safe.t
val term_to_yojson : term -> Yojson.Safe.t
val for_clause_to_yojson : for_clause -> Yojson.Safe.t
val wordlist_to_yojson : wordlist -> Yojson.Safe.t
val case_clause_to_yojson : case_clause -> Yojson.Safe.t
val case_list_ns_to_yojson : case_list_ns -> Yojson.Safe.t
val case_list_to_yojson : case_list -> Yojson.Safe.t
val case_item_ns_to_yojson : case_item_ns -> Yojson.Safe.t
val case_item_to_yojson : case_item -> Yojson.Safe.t
val pattern_to_yojson : pattern -> Yojson.Safe.t
val if_clause_to_yojson : if_clause -> Yojson.Safe.t
val else_part_to_yojson : else_part -> Yojson.Safe.t
val while_clause_to_yojson : while_clause -> Yojson.Safe.t
val until_clause_to_yojson : until_clause -> Yojson.Safe.t
val function_definition_to_yojson : function_definition -> Yojson.Safe.t
val function_body_to_yojson : function_body -> Yojson.Safe.t
val fname_to_yojson : fname -> Yojson.Safe.t
val brace_group_to_yojson : brace_group -> Yojson.Safe.t
val do_group_to_yojson : do_group -> Yojson.Safe.t
val simple_command_to_yojson : simple_command -> Yojson.Safe.t
val cmd_name_to_yojson : cmd_name -> Yojson.Safe.t
val cmd_word_to_yojson : cmd_word -> Yojson.Safe.t
val cmd_prefix_to_yojson : cmd_prefix -> Yojson.Safe.t
val cmd_suffix_to_yojson : cmd_suffix -> Yojson.Safe.t
val redirect_list_to_yojson : redirect_list -> Yojson.Safe.t
val io_redirect_to_yojson : io_redirect -> Yojson.Safe.t
val io_file_to_yojson : io_file -> Yojson.Safe.t
val filename_to_yojson : filename -> Yojson.Safe.t
val io_here_to_yojson : io_here -> Yojson.Safe.t
val here_end_to_yojson : here_end -> Yojson.Safe.t
val newline_list_to_yojson : newline_list -> Yojson.Safe.t
val linebreak_to_yojson : linebreak -> Yojson.Safe.t
val separator_op_to_yojson : separator_op -> Yojson.Safe.t
val separator_to_yojson : separator -> Yojson.Safe.t
val sequential_sep_to_yojson : sequential_sep -> Yojson.Safe.t
val word_to_yojson : word -> Yojson.Safe.t
val word_cst_to_yojson : word_cst -> Yojson.Safe.t
val word_component_to_yojson : word_component -> Yojson.Safe.t
val bracket_expression_to_yojson : bracket_expression -> Yojson.Safe.t
val matching_list_to_yojson : matching_list -> Yojson.Safe.t
val nonmatching_list_to_yojson : nonmatching_list -> Yojson.Safe.t
val bracket_list_to_yojson : bracket_list -> Yojson.Safe.t
val follow_list_to_yojson : follow_list -> Yojson.Safe.t
val expression_term_to_yojson : expression_term -> Yojson.Safe.t
val single_expression_to_yojson : single_expression -> Yojson.Safe.t
val range_expression_to_yojson : range_expression -> Yojson.Safe.t
val start_range_to_yojson : start_range -> Yojson.Safe.t
val end_range_to_yojson : end_range -> Yojson.Safe.t
val collating_symbol_to_yojson : collating_symbol -> Yojson.Safe.t
val equivalence_class_to_yojson : equivalence_class -> Yojson.Safe.t
val character_class_to_yojson : character_class -> Yojson.Safe.t
val class_name_to_yojson : class_name -> Yojson.Safe.t
val character_range_to_yojson : character_range -> Yojson.Safe.t
val variable_to_yojson : variable -> Yojson.Safe.t
val variable_attribute_to_yojson : variable_attribute -> Yojson.Safe.t
val subshell_kind_to_yojson : subshell_kind -> Yojson.Safe.t
val name_to_yojson : name -> Yojson.Safe.t
val assignment_word_to_yojson : assignment_word -> Yojson.Safe.t
val io_number_to_yojson : io_number -> Yojson.Safe.t
val program'_to_yojson : program' -> Yojson.Safe.t
val complete_commands'_to_yojson : complete_commands' -> Yojson.Safe.t
val complete_command'_to_yojson : complete_command' -> Yojson.Safe.t
val clist'_to_yojson : clist' -> Yojson.Safe.t
val and_or'_to_yojson : and_or' -> Yojson.Safe.t
val pipeline'_to_yojson : pipeline' -> Yojson.Safe.t
val pipe_sequence'_to_yojson : pipe_sequence' -> Yojson.Safe.t
val command'_to_yojson : command' -> Yojson.Safe.t
val compound_command'_to_yojson : compound_command' -> Yojson.Safe.t
val subshell'_to_yojson : subshell' -> Yojson.Safe.t
val compound_list'_to_yojson : compound_list' -> Yojson.Safe.t
val term'_to_yojson : term' -> Yojson.Safe.t
val for_clause'_to_yojson : for_clause' -> Yojson.Safe.t
val wordlist'_to_yojson : wordlist' -> Yojson.Safe.t
val case_clause'_to_yojson : case_clause' -> Yojson.Safe.t
val case_list_ns'_to_yojson : case_list_ns' -> Yojson.Safe.t
val case_list'_to_yojson : case_list' -> Yojson.Safe.t
val case_item_ns'_to_yojson : case_item_ns' -> Yojson.Safe.t
val case_item'_to_yojson : case_item' -> Yojson.Safe.t
val pattern'_to_yojson : pattern' -> Yojson.Safe.t
val if_clause'_to_yojson : if_clause' -> Yojson.Safe.t
val else_part'_to_yojson : else_part' -> Yojson.Safe.t
val while_clause'_to_yojson : while_clause' -> Yojson.Safe.t
val until_clause'_to_yojson : until_clause' -> Yojson.Safe.t
val function_definition'_to_yojson : function_definition' -> Yojson.Safe.t
val function_body'_to_yojson : function_body' -> Yojson.Safe.t
val fname'_to_yojson : fname' -> Yojson.Safe.t
val brace_group'_to_yojson : brace_group' -> Yojson.Safe.t
val do_group'_to_yojson : do_group' -> Yojson.Safe.t
val simple_command'_to_yojson : simple_command' -> Yojson.Safe.t
val cmd_name'_to_yojson : cmd_name' -> Yojson.Safe.t
val cmd_word'_to_yojson : cmd_word' -> Yojson.Safe.t
val cmd_prefix'_to_yojson : cmd_prefix' -> Yojson.Safe.t
val cmd_suffix'_to_yojson : cmd_suffix' -> Yojson.Safe.t
val redirect_list'_to_yojson : redirect_list' -> Yojson.Safe.t
val io_redirect'_to_yojson : io_redirect' -> Yojson.Safe.t
val io_file'_to_yojson : io_file' -> Yojson.Safe.t
val filename'_to_yojson : filename' -> Yojson.Safe.t
val io_here'_to_yojson : io_here' -> Yojson.Safe.t
val here_end'_to_yojson : here_end' -> Yojson.Safe.t
val newline_list'_to_yojson : newline_list' -> Yojson.Safe.t
val linebreak'_to_yojson : linebreak' -> Yojson.Safe.t
val separator_op'_to_yojson : separator_op' -> Yojson.Safe.t
val separator'_to_yojson : separator' -> Yojson.Safe.t
val sequential_sep'_to_yojson : sequential_sep' -> Yojson.Safe.t
val word'_to_yojson : word' -> Yojson.Safe.t
val name'_to_yojson : name' -> Yojson.Safe.t
val assignment_word'_to_yojson : assignment_word' -> Yojson.Safe.t
class virtual +'a iter : object ... end
class virtual +'a map : object ... end
class virtual +'a reduce : object ... end
class virtual +'a mapreduce : object ... end
class virtual +'a iter2 : object ... end
class virtual +'a map2 : object ... end
class virtual +'a reduce2 : object ... end