Lang.Common
Common base classes for defining a parseable object.
type parseable =
| Bind of bind
| Or of parseable list
A choice between a given list of alternatives. Backtracking occurs within a single Or pattern.
*)| Seq of parseable list
A sequential composition of the given parseables.
*)| Lit of string
A literal string.
*)| Space
Zero or more within-line space characters (space or tab).
*)| Return of string
A parser that always succeeds, returning the given string. Consumes no input.
*)| Digits
One or more decimal digits (without sign characters).
*)| Eof
A 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 ... end
module StringMap : sig ... end
Currently, 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.t
Functions 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 ... end
val binding : StringMap.key -> output -> bindings
Adds 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 : bindings
val bindings_is_empty : bindings -> bool
include sig ... end
val pp_parseable : Stdlib.Format.formatter -> Lang__.Types.parseable -> unit
val pp_bind : Stdlib.Format.formatter -> Lang__.Types.bind -> unit
val parseable_to_yojson : Lang__.Types.parseable -> Yojson.Safe.t
val parseable_of_yojson :
Yojson.Safe.t ->
Lang__.Types.parseable Ppx_deriving_yojson_runtime.error_or
val bind_to_yojson : Lang__.Types.bind -> Yojson.Safe.t
val bind_of_yojson :
Yojson.Safe.t ->
Lang__.Types.bind Ppx_deriving_yojson_runtime.error_or
val literals : string list -> parseable
Creates 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 : parseable
val empty : parseable
A parser that always succeeds, consumes no input (abbreviation for Seq []
).
val fail : parseable
A 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 -> string
Produces 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 -> string
Given a Format
-style pp
function, converts it to a simple function returning a string.
val show_stringmap : ('a -> string) -> 'a StringMap.t -> string
Shows a string map.
val show_bindings : output list StringMap.t -> string
Shows a map of binding values.
val show_parse_output : (output * output list StringMap.t) -> string
Shows a pair of output and bindings, as produced by the parser.
val show_parse_result :
(output * output list StringMap.t, string) result ->
string
Shows the result of running a parseable through Angstrom.
val show_result : ('a -> string) -> ('a, string) result -> string