module Lexingutil: sig end
These functions are designed to assist with ocamllex lexers or anything
that uses the built-in Lexing module.
exception ParsingSyntaxError of string
Lexingutil.raise_syntax_error
function will raise this exception as well.val countline : Lexing.lexbuf -> unit
You can use countline in a rule in your .mll file. For instance,
this comes from the ConfigParser
module:
rule loken = parse
eol { countline lexbuf; loken lexbuf }
This will cause the end-of-line (the eol pattern is defined outside this
example) to increase the counter but then be otherwise ignored.
val raise_syntax_error : string -> Lexing.position -> 'a
Lexingutil.ParsingSyntaxError
. It combines
the given message with the given position to generate an error message that
give the offset, line number, and character number of the error.
You can use it from a parser like this:
| error { raise_syntax_error "ConfigParser" (Parsing.symbol_start_pos () ) }
Or, from a lexer like this:
| (_) as error { raise_syntax_error "ConfigParser" (lexeme_start_p lexbuf) }
The result will look like this:
ConfigParser: Syntax error in <unknown>, at or before offset 6 (line 2, char 1)