Legend:
Library
Module
Module type
Parameter
Class
Class type
JavaScript Object Notation (JSON) input scanner.
Overview
Functions that scan Unicode text for JSON interchange language syntax. A low-level lexical token scanner is provided for monadic parsing of any valid JSON text, including infinite streams. Higher-level scanners are provided for composing bespoke parsers according to a required schema. A scanner is also provided for input of arbitrary finite JSON values.
Use collect s to bind in sequence every monad value in the finite sequence s and collect all the returned values. Returns (n, s) where n is the number of values collected and s is the list of values in reverse order, i.e. from last collected to first collected. Never returns and exhausts all memory if s never terminates.
Use pos mark to make a unit value attributed with the position of captured mark. If the mark was captured at the end of the stream, then the result is an implicit form.
The ignore scanner. Use ign f to make a scanner that scans the input while applying f to each symbol returns true, then produces a unit form that annotates the span of ignored symbols. Produces an implicit unit form if the end of input has already been reached.
The opaque value form scanner composer. Use ntyp n p to make a scanner that encloses the value contained in the form produced by p in an opaque value with the runtime type indicated by n and returns its form in the same position.
The visitor scanner composer. Use vis ?a ?b f v to compose a scanner that recognizes a sequence of elements in the input stream by applying a visitor function f at each element to obtain its scanner. The first element is visited with the initializer v, and each following element is visited with the value returned by the preceding scanner.
If ~a is used, then it specifies the minimum number of elements to visit. If ~b is used then it specifies the maximum number of elements to visit. Composition raises Invalid_argument if a < 0 or b < a.
The homogenous list scanner composer. Use seq ?a ?b p to create a new scanner that uses p to recognize and produce, in order, each element in a sequence of elements in the input stream.
If ~a is used, then it specifies the minimum number of elements that must be recognized and produced in the output. If ~b is used then it specifies the maximum number of elements to recognize. Composition raises Invalid_argument if a < 0 or b < a.
The bounded multiple choice scanner. Use alt ps to create a scanner that produces the output from the first scanner ps that produces. If no scanner in ps produces output, then the resulting scanner does not produce.
The unbounded multiple choice scanner. Use alt ps to create a scanner that produces the output from the first scanner ps that produces. If no scanner in ps produces output, then the resulting scanner does not produce.
Use or_fail msg p to make a scanner that raises Bad_syntax with msg if p does not recognize its input. It may be convenient to call this function with a pipeline operator, i.e. p |> or_fail "reasons".
Use req ~x p to make a scanner that either produces the output of p or raises x. If p does not produce and ?x is not provided, then it raises Not_found.
Use reqf ~xf p to make a scanner that either produces the output of p or captures a mark at the current input and applies it to xf to raise an exception. If ?xf is not provided, then raises Not_found.
The conversion scanner. Use cast f p to create a scanner produces the result of applying f to the value recognized by p. If f raises Not_found then the resulting scanner does not produce. If f raises Failure s then it will be caught and Bad_syntax will be raised with the corresponding message decorated with the position.
The error check scanner. Use ck p to create a new scanner that either produces either Ok v if p produces v or Error x if scanning the input with p raises the exception x.
The error recovery scanner. Use sync p to scan the input with p until it produces or reaches the end of input. Produces Some v if p ever produces v, otherwise produces None if the end of input is reached without p producing a value.
Use lift p s to map s into a persistent sequence of the values produced by p. If ~start is provided, then it specifies the starting position of the first symbol in s.
Use of_seq p s to parse s with p and return the result. Raises Not_found if p does not recognize the entire sequence of s. If ~start is provided, then it specifies the starting position of the first symbol in s.
Use lift_staged p s to lift s into the first stage token sequence, then map it into a persistent sequence of the values produced by p. If ~start is provided, then it specifies the starting position of the first symbol in s.
Use of_seq_staged p s to lift s into the first stage token sequence, then parse it with p, and return the result. Raises Not_found if p does not recognize the entire sequence of s. If ~start is provided, then it specifies the starting position of the first symbol in s.
An opaque value parser created by Opaque.value with default mode, which maps its output so that objects are witnessed by the following type nym instead: