package ocaml-webworker

  1. Overview
  2. Docs
type position = Lexing.position = {
  1. pos_fname : string;
  2. pos_lnum : int;
  3. pos_bol : int;
  4. pos_cnum : int;
}
include module type of struct include Lexing end with type position := position
Positions
val dummy_pos : position

A value of type position, guaranteed to be different from any valid position.

Lexer buffers
type lexbuf = Lexing.lexbuf = {
  1. refill_buff : lexbuf -> unit;
  2. mutable lex_buffer : bytes;
  3. mutable lex_buffer_len : int;
  4. mutable lex_abs_pos : int;
  5. mutable lex_start_pos : int;
  6. mutable lex_curr_pos : int;
  7. mutable lex_last_pos : int;
  8. mutable lex_last_action : int;
  9. mutable lex_eof_reached : bool;
  10. mutable lex_mem : int array;
  11. mutable lex_start_p : position;
  12. mutable lex_curr_p : position;
}

The type of lexer buffers. A lexer buffer is the argument passed to the scanning functions defined by the generated scanners. The lexer buffer holds the current state of the scanner, plus a function to refill the buffer from the input.

At each token, the lexing engine will copy lex_curr_p to lex_start_p, then change the pos_cnum field of lex_curr_p by updating it with the number of characters read since the start of the lexbuf. The other fields are left unchanged by the lexing engine. In order to keep them accurate, they must be initialised before the first use of the lexbuf, and updated by the relevant lexer actions (i.e. at each end of line -- see also new_line).

val from_channel : Pervasives.in_channel -> lexbuf

Create a lexer buffer on the given input channel. Lexing.from_channel inchan returns a lexer buffer which reads from the input channel inchan, at the current reading position.

val from_string : string -> lexbuf

Create a lexer buffer which reads from the given string. Reading starts from the first character in the string. An end-of-input condition is generated when the end of the string is reached.

val from_function : (bytes -> int -> int) -> lexbuf

Create a lexer buffer with the given function as its reading method. When the scanner needs more characters, it will call the given function, giving it a byte sequence s and a byte count n. The function should put n bytes or fewer in s, starting at index 0, and return the number of bytes provided. A return value of 0 means end of input.

Functions for lexer semantic actions

The following functions can be called from the semantic actions of lexer definitions (the ML code enclosed in braces that computes the value returned by lexing functions). They give access to the character string matched by the regular expression associated with the semantic action. These functions must be applied to the argument lexbuf, which, in the code generated by ocamllex, is bound to the lexer buffer passed to the parsing function.

val lexeme : lexbuf -> string

Lexing.lexeme lexbuf returns the string matched by the regular expression.

val lexeme_char : lexbuf -> int -> char

Lexing.lexeme_char lexbuf i returns character number i in the matched string.

val lexeme_start : lexbuf -> int

Lexing.lexeme_start lexbuf returns the offset in the input stream of the first character of the matched string. The first character of the stream has offset 0.

val lexeme_end : lexbuf -> int

Lexing.lexeme_end lexbuf returns the offset in the input stream of the character following the last character of the matched string. The first character of the stream has offset 0.

val lexeme_start_p : lexbuf -> position

Like lexeme_start, but return a complete position instead of an offset.

val lexeme_end_p : lexbuf -> position

Like lexeme_end, but return a complete position instead of an offset.

val new_line : lexbuf -> unit

Update the lex_curr_p field of the lexbuf to reflect the start of a new line. You can call this function in the semantic action of the rule that matches the end-of-line character.

  • since 3.11.0
Miscellaneous functions
val flush_input : lexbuf -> unit

Discard the contents of the buffer and reset the current position to 0. The next use of the lexbuf will trigger a refill.

val move : lexbuf -> position -> unit
val from_strings : ?empty:bool Pervasives.ref -> ?position:position -> string -> (unit -> string) -> lexbuf
val make_pos : ?pos_fname:string -> (int * int) -> position
val column : position -> int
val set_column : position -> int -> position
val split_pos : position -> int * int
val compare_pos : position -> position -> int
val print_position : unit -> position -> string
val immediate_pos : lexbuf -> position
val json_of_position : position -> [> `Assoc of (string * [> `Int of int ]) list ]
val min_pos : position -> position -> position
val max_pos : position -> position -> position
OCaml

Innovation. Community. Security.