package orsetto
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f64814687276bad56483b2b8dfaaf70d0d6485f67fe5d44bff34bfa47af1896e
md5=3a15a377800cf988a310b4082406c685
doc/orsetto.cf/Cf_scan/ASCII/index.html
Module Cf_scan.ASCII
This module provides simple scanners for analyzing texts encoded in 8bit-extended ASCII text encodings, e.g. ISO 8859 Latin, without any concept of stream position.
Include the basic scanner for simple ASCII character sequences.
include Simple.Profile with type symbol := char
include Cf_monad.Unary.Profile with type +'r t := 'r t
Module inclusions from Cf_monad_core and Cf_seqmonad.
include Cf_monad.Core.Unary.Profile with type 'r t := 'r t
val return : 'r -> 'r tUse return a to apply the binding to a.
Use map m f to return the result of applying f to the value returned by m.
module Infix : Cf_monad_core.Unary.Infix with type 'r t := 'r tOpen Infix to include the infix monad operators.
include Cf_seqmonad.Functor.Unary with type 'r t := 'r t
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.
val nil : 'r tA scanner that never produces any value.
val fin : bool tA scanner that returns true at the end of the input sequence, otherwise returns false.
Backtracking
val pos : mark -> unitUse pos mark to make a unit value attributed with the position of captured mark. Raises Not_found if mark was captured at the end of the input stream.
Terminal Scanner
val any : char tThe universal symbol scanner. Recognizes any symbol in the input stream and produces its form. Does not produce anything at the end of input.
val one : char -> char tThe literal symbol scanner. Use one symbol to make a scanner that recognizes symbol in the input stream and produces its form.
val sat : (char -> bool) -> char tThe symbol satisfier scanner. Use sat f to make a scanner that recognizes any symbol for which applying f returns true and produces its form.
val ign : (char -> bool) -> unit tThe 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.
val tok : (char -> 'r option) -> 'r tThe symbolic token scanner. Use tok f to make a scanner that recognizes any symbol for which applying f returns Some v, then produces the form of v.
Scanner Composers
val ntyp : 'r Cf_type.nym -> 'r t -> Cf_type.opaque tThe 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 default value scanner. Use dflt v p to produce the output of p or the default value v if p does not produce output.
The optional scanner composer. Use opt p to make a scanner that produces either Some v if p produces v otherwise None.
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.
Error Parsers
val fail : string -> 'r tUse fail msg to raise Bad_syntax with msg optionally annotated with the current position.
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".
val err : ?x:exn -> unit -> 'r tUse err ~x () to make a scanner that raises x. If ?x is not provided, then it raises Not_found.
Use errf ~xf () to make a scanner that captures a mark and applies it to xf to raise an exception. If ?xf is not provided, then raises Not_found.
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 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.
Elaboration
val lift : ?start:Simple.position -> 'r t -> char Seq.t -> 'r Seq.tUse 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.
val of_seq : ?start:Simple.position -> 'r t -> char Seq.t -> 'rUse 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.
module Affix : sig ... endCombinator operators
val rws : unit tThe required white space parser, which recognizes a sequence of one or more white space characters.
val rwsl : unit tThe required line-breaking white space parser, which recognizes a sequence of one or more white space characters excluding line breaks.
val ows : unit option tThe optional white space parser, which recognizes a sequence of zero or more white space characters. It is an abbreviation of opt rws.
val owsl : unit option tThe optional line-breaking white space parser, which recognizes a sequence of zero or more white space characters excluding line breaks. It is an abbreviation of opt rwsl.
val lit : string -> 'r -> 'r tUse lit s obj to obtain a parser on character input sequences that produces the output obj when it recognizes the literal s in the input.
val fmt :
('a, Scanf.Scanning.in_channel, 'b, 'c -> 'r, 'a -> 'd, 'd) format6 ->
'c ->
'r tUse fmt s c to make a parser that uses the standard Scanf library to parse the input according to the format s, applies the recognized values to the receiver c, and produces the result. Exceptions raised by the Scanf library functions are not intercepted.
Note Well: The Scanf library is not intended for heavy-duty lexical analysis. In particular, a field width should be used in the last format specifier of s to prevent the over-consumption of input stream characters. For example, fmt "%d" c will consume the 'x' character in the input stream "1000x" while fmt "%4d" c will not.
val escape : char -> char -> char tUse escape up dn to create a minimal escape parser that recognizes up followed either by dn or another up. The character following the first up is returned.
The quoted string parser. Use quoted c to recognize a string delimited by the character c. Use the ~esc argument to specify an escape parser. The default escape parser is equivalent to ~esc:(escape '\\' c).
val of_string : 'a t -> string -> 'aUse of_string p s to parse s with p and return the result. Raises Not_found if p does not recognize the entire text of s.