MenhirLib.ErrorReportsThis module offers functions that can help produce syntax error messages.
A two-place buffer of type 'a buffer holds zero, one, or two elements of type 'a. Some of the functions below keep track of the start and end positions of the last two tokens in a two-place buffer. This helps nicely show where a syntax error took place.
val wrap :
((Lexing.lexbuf -> 'token) as 'lexer) ->
(Lexing.position * Lexing.position) buffer * 'lexerwrap lexer returns a pair of a new (initially empty) buffer and a lexer which internally relies on lexer and updates buffer on the fly whenever a token is demanded.
The type of the buffer is (position * position) buffer, which means that it stores two pairs of positions, which are the start and end positions of the last two tokens.
The type of the lexer is lexbuf -> 'token. The start and end positions of each token are read from lexbuf.
val wrap_supplier :
((unit -> 'token * Lexing.position * Lexing.position) as 'lexer) ->
(Lexing.position * Lexing.position) buffer * 'lexerwrap_supplier is analogous to wrap, except the type of the lexer is unit -> 'token * position * position. No lexbuf is involved.
val show : ('a -> string) -> 'a buffer -> stringshow f buffer prints the contents of the buffer, producing a string that is typically of the form "after '%s' and before '%s'". The function f is used to print an element. The buffer MUST be nonempty.
val last : 'a buffer -> 'alast buffer returns the last element of the buffer. The buffer MUST be nonempty.
val extract : string -> (Lexing.position * Lexing.position) -> stringextract text (pos1, pos2) extracts the sub-string of text delimited by the positions pos1 and pos2.
sanitize text eliminates any special characters from the text text. A special character is a character whose ASCII code is less than 32. Every special character is replaced with a single space character.
compress text replaces every run of at least one whitespace character with exactly one space character.
shorten k text limits the length of text to 2k+3 characters. If the text is too long, a fragment in the middle is replaced with an ellipsis.