module Sedlexing:sig
..end
sedlex
.int
in the range 0..0x10ffff
) instead
of bytes (OCaml type: char
).
It is possible to have sedlex-generated lexers work on a custom
implementation for lex buffers. To do this, define a module L
which implements the start
, next
, mark
and backtrack
functions (See the Internal Interface section below for a
specification). They need not work on a type named lexbuf
: you
can use the type name you want. Then, just do in your
sedlex-processed source, bind this module to the name Sedlexing
(for instance, with a local module definition: let module Sedlexing
= L in ...
.
Of course, you'll probably want to define functions like lexeme
to
be used in the lexers semantic actions.
type
lexbuf
exception InvalidCodepoint of int
exception MalFormed
Utf8
and Utf16
modules to report
strings which do not comply to the encoding.val create : (int array -> int -> int -> int) -> lexbuf
a
, a position pos
and a code point count n
. The
function should put n
code points or less in a
, starting at
position pos
, and return the number of characters provided. A
return value of 0 means end of input.val from_gen : int Gen.t -> lexbuf
val from_stream : int Stream.t -> lexbuf
val from_int_array : int array -> lexbuf
val lexeme_start : lexbuf -> int
Sedlexing.lexeme_start lexbuf
returns the offset in the
input stream of the first code point of the matched string.
The first code point of the stream has offset 0.val lexeme_end : lexbuf -> int
Sedlexing.lexeme_end lexbuf
returns the offset in the input
stream of the character following the last code point of the
matched string. The first character of the stream has offset
0.val loc : lexbuf -> int * int
Sedlexing.loc lexbuf
returns the pair
(Sedlexing.lexeme_start lexbuf,Sedlexing.lexeme_end
lexbuf)
.val lexeme_length : lexbuf -> int
Sedlexing.loc lexbuf
returns the difference
(Sedlexing.lexeme_end lexbuf) - (Sedlexing.lexeme_start
lexbuf)
, that is, the length (in code points) of the matched
string.val lexeme : lexbuf -> int array
Sedlexing.lexeme lexbuf
returns the string matched by the
regular expression as an array of Unicode code point.val lexeme_char : lexbuf -> int -> int
Sedlexing.lexeme_char lexbuf pos
returns code point number pos
in
the matched string.val sub_lexeme : lexbuf -> int -> int -> int array
Sedlexing.lexeme lexbuf pos len
returns a substring of the string
matched by the regular expression as an array of Unicode code point.val rollback : lexbuf -> unit
Sedlexing.rollback lexbuf
puts lexbuf
back in its configuration before
the last lexeme was matched. It is then possible to use another
lexer to parse the same characters again. The other functions
above in this section should not be used in the semantic action
after a call to Sedlexing.rollback
.sedlex
. The lexer buffers have a unique internal slot that can store
an integer. They also store a "backtrack" position.val start : lexbuf -> unit
start t
informs the lexer buffer that any
code points until the current position can be discarded.
The current position become the "start" position as returned
by Sedlexing.lexeme_start
. Moreover, the internal slot is set to
-1
and the backtrack position is set to the current position.val next : lexbuf -> int
next lexbuf
extracts the next code point from the
lexer buffer and increments to current position. If the input stream
is exhausted, the function returns -1
.val mark : lexbuf -> int -> unit
mark lexbuf i
stores the integer i
in the internal
slot. The backtrack position is set to the current position.val backtrack : lexbuf -> int
backtrack lexbuf
returns the value stored in the
internal slot of the buffer, and performs backtracking
(the current position is set to the value of the backtrack position).module Latin1:sig
..end
module Utf8:sig
..end
module Utf16:sig
..end