Module BNFparseutil


module BNFparseutil: sig .. end
Character parsing utilities
Author(s): Copyright (C) 2004 John Goerzen


General Parsing Utilities

val s_and : ('a Stream.t -> 'b) list -> 'a Stream.t -> 'b list
Used to ensure that all conditions are met at the same point on a stream. Takes a list of stream parsers that all return the same type of data and evaluates them all. If all succeed (don't raise any exceptions), then a list of results from those parsers is returned.

Note: It is extremely important that you make all your conditions consume the same amount of data from the stream. Otherwise, undefined results will occur.

val eof : 'a Stream.t -> unit
Useful to testing to see if the end-of-file has been reached. This is an alias for Stream.empty.

Character-Specific Parsing Utilities

val insens : bool
Default value for case-insensitive comparisons. Defaults to false, meaning comparisons are case-sensitive. Optional i arguments to functions in this module take a bool specifying whether or not to use case-insensitive comparisons. The default value for i in those functions is this value.

type repatt =
| C of char (*Match a single character*)
| R of char * char (*Match a single character within the inclusive range of the two characters given*)
Used for parsing character ranges
val range : ?i:bool -> repatt list -> char Stream.t -> char
Stream parser: find a single character in the given range.
val range_n : ?i:bool -> repatt list -> char Stream.t -> char
Stream parser: find any character NOT in the given range.
val mstring : ?i:bool -> string -> char Stream.t -> string
Stream parser: find the given string in a character string.
val chr : int -> char
Returns the character given by the specified integer; an alias for Char.chr.
val optparse : ('a -> char) -> 'a -> string
This function is useful for parsing zero or more occurances of a certain element. Similar to Streamutil.optparse, but works only on character strings and returns a string.
Returns A string; may be empty.
func : The parser function. Will be called repeatedly until Stream.Failure is raised.
args : Passed to func.
val optparse_1 : ('a -> char) -> 'a -> string
Same as optparse, but forces to match at least once. funchead is applied to the first element; functail to all the rest. Similar to Streamutil.optparse_1, but works only on character strings and returns a string.
funchead : Function to apply to all arguments
args : Passed to the various functions