Lang.CommonCommon base classes for defining a parseable object.
type parseable = | Bind of bind| Or of parseable listA choice between a given list of alternatives. Backtracking occurs within a single Or pattern.
*)| Seq of parseable listA sequential composition of the given parseables.
*)| Lit of stringA literal string.
*)| SpaceZero or more within-line space characters (space or tab).
*)| Return of stringA parser that always succeeds, returning the given string. Consumes no input.
*)| DigitsOne or more decimal digits (without sign characters).
*)| EofA parser that succeeds only at the end of the text.
*)A parseable structure.
The syntax allowed is intentionally very restrictive, to allow for tractable analysis and manipulation. Grammars definable by this structure will have no unbounded repetition and no context-sensitivity. This makes it less powerful, even, than the regular languages.
module StringSet : sig ... endmodule StringMap : sig ... endCurrently, all parseables will produce string list when parsed. This explicit type helps avoid confusion with other lists, especially in the case of an output list.
Functions on output objects.
type bindings = output list StringMap.tFunctions on bindings objects. These must be used instead of the normal map functions to maintain the semantics of bindings as a list of parse outputs.
include sig ... endval binding : StringMap.key -> output -> bindingsAdds a new output to the given binding name. The new output is added to the front of the output list.
Merges two binding maps, with the interpretation that the left bindings were parsed before the right bindings - not commutative!
Pops one output associated to given name from the bindings. Returns the output and the modified bindings map.
Partial order on bindings, comparing two bindings by the number of outputs they contain.
A bindings map b1 is less than or equal to b2 if: for every entry (k,v1) in b1, b2 has a mapping for k and v1 is a suffix of f2(k). For the purpose of this comparison, a mapping to the empty list is treated as if no mapping was present.
val bindings_empty : bindingsval bindings_is_empty : bindings -> boolinclude sig ... endval pp_parseable : Stdlib.Format.formatter -> Lang__.Types.parseable -> unitval pp_bind : Stdlib.Format.formatter -> Lang__.Types.bind -> unitval parseable_to_yojson : Lang__.Types.parseable -> Yojson.Safe.tval parseable_of_yojson :
Yojson.Safe.t ->
Lang__.Types.parseable Ppx_deriving_yojson_runtime.error_orval bind_to_yojson : Lang__.Types.bind -> Yojson.Safe.tval bind_of_yojson :
Yojson.Safe.t ->
Lang__.Types.bind Ppx_deriving_yojson_runtime.error_orval literals : string list -> parseableCreates a parseable which accepts any of the given strings.
Note: the parser will re-order literals to be longest first, to avoid problems when one alternative is a prefix of another.
val eof : parseableval empty : parseableA parser that always succeeds, consumes no input (abbreviation for Seq []).
val fail : parseableA parser that always fails (abbreviation for Or []).
Parses the given parser in between the given l and r delimiters. Delimeters default to open- and close- square brackets.
Returns a parser which sequences the two parsers. Performs minor optimisation when one or both of its arguments is Seq, fusing them together if possible.
Repetition combinator, accepting repetitions of p at least min and at most max times (both inclusive). Requires both bounds be non-negative.
val describe_parseable : parseable -> stringProduces a human-readable description of the given parseable.
For example,
describe_parseable @@ optional (Or [Lit "a"; Lit "b"])produces ("a" | "b")?.
val show : (Stdlib.Format.formatter -> 'a -> unit) -> 'a -> stringGiven a Format-style pp function, converts it to a simple function returning a string.
val show_stringmap : ('a -> string) -> 'a StringMap.t -> stringShows a string map.
val show_bindings : output list StringMap.t -> stringShows a map of binding values.
val show_parse_output : (output * output list StringMap.t) -> stringShows a pair of output and bindings, as produced by the parser.
val show_parse_result :
(output * output list StringMap.t, string) result ->
stringShows the result of running a parseable through Angstrom.
val show_result : ('a -> string) -> ('a, string) result -> string