A trustworthy parser for POSIX shell
Module Morbig

Main API points

Parsing shell scripts
val parse_file : string -> CST.program

parse_file filename performs the syntactic analysis of filename and returns a concrete syntax tree if filename content is syntactically correct.

Raises exceptions from Errors.

val parse_string : string -> string -> CST.program

parse_string filename content is similar to parse_file except the script source code is provided as a string.

Serialization of CST
val load_binary_cst : in_channel -> CST.program

load_binary_cst cin retrieves a serialized CST from input_channel cin.

val save_binary_cst : out_channel -> CST.program -> unit

save_binary_cst cout cst stores a serialized cst in cout.

val load_json_cst : in_channel -> CST.program

load_json_cst cin retrieves a CST in JSON format from input_channel cin.

val save_json_cst : out_channel -> CST.program -> unit

save_json_cst cout cst stores a cst using JSON format in cout.

val save_dot_cst : out_channel -> CST.program -> unit

save_dot_cst cout cst stores a cst using DOT format in cout.

CST helpers
val on_located : ( 'a -> 'b ) -> 'a CST.located -> 'b

on_located f applies f on a located value, preserving its location.

val start_of_position : CST.position -> Lexing.position

start_of_position p returns the beginning of a position p.

val end_of_position : CST.position -> Lexing.position

end_of_position p returns the end of a position p.

val filename_of_position : CST.position -> string

filename_of_position p returns the filename of a position p.

val string_of_lexing_position : Lexing.position -> string

string_of_lexing_position p returns a human-readable representation of the lexing position p, using a format recognized by Emacs, and other decent editors.

val remove_quotes : string -> string

remove_quotes s yields a copy of string s, with all quotes removed as described in the POSIX specification.

Other modules

module Aliases : sig ... end
module Assignment : sig ... end
module CSTHelpers : sig ... end
module CST : sig ... end
module Debug : sig ... end
module Engine : sig ... end
module Errors : sig ... end
module ExtMenhirLib : sig ... end
module HereDocument : sig ... end

HereDocument.Lexer handles here documents. It does:

module JsonHelpers : sig ... end
module Keyword : sig ... end
module Name : sig ... end
module Nesting : sig ... end
module Options : sig ... end
module Parser : sig ... end
module Prelexer : sig ... end

This module implements the token recognizer when it is not in the mode that recognizes here-documents, and in cases where the recognition of tokens is independent from the parsing context, as specified by:

module PrelexerState : sig ... end
module Pretokenizer : sig ... end
module Pretoken : sig ... end
module QuoteRemoval : sig ... end
module RecursiveParser : sig ... end
module Scripts : sig ... end
module Token : sig ... end