Lexer(3)

πŸ’– Lexer(3) πŸ’–

okay so bestie, welcome to Lexer(3) from the OCaml library β€” the page for the lexical analyzer. Yes, the manual name is literally Lexer(3), and we are reading it together like the iconic little docs nerds we are. 🫢✨

🌸 NAME 🌸

Lexer β€” the lexical analyzer. That's the name, that's the vibe, periodt. πŸ’…

🧚 Module 🧚

Module Lexer β€” and the signature is right here:

Module Lexer
 : sig end

✨ Documentation ✨

Module Lexer : sig end shows up again in the docs, because of course it does. Then comes the sentence The lexical analyzer β€” main character energy, honestly. 🌟

Warning: this module is unstable and part of Compiler_libs .

Not me being dramatic β€” that's literally the warning. πŸ’€

Here are the values, in order, no skipping:

  • val init : ?keyword_edition:(int * int) option * string list -> unit -> unit β€” the init signature, exactly as written. Keep the ?keyword_edition bits and the double -> unit -> unit energy. ✨
  • val token : Lexing.lexbuf -> Parser.token β€” takes a Lexing.lexbuf, gives you a Parser.token.
  • val skip_hash_bang : Lexing.lexbuf -> unit β€” takes a Lexing.lexbuf and returns unit. The name says skip_hash_bang, and we are respectfully not adding extra lore. πŸŽ€

Then we hit type error =, and every single constructor is here, bestie:

type error =
 | Illegal_character of char
 | Illegal_escape of string * string option
 | Reserved_sequence of string * string option
 | Unterminated_comment of Location.t
 | Unterminated_string
 | Unterminated_string_in_comment of Location.t * Location.t
 | Empty_character_literal
 | Keyword_as_label of string
 | Capitalized_label of string
 | Invalid_literal of string
 | Invalid_directive of string * string option
 | Invalid_encoding of string
 | Invalid_char_in_ident of Uchar.t
 | Non_lowercase_delimiter of string
 | Capitalized_raw_identifier of string
 | Unknown_keyword of string

And it comes with this exception, exactly:

exception Error of error * Location.t

More values, keep scrolling bestie:

  • val in_comment : unit -> bool β€” takes unit, returns a bool, so it's giving yes/no energy. πŸ’œ
  • val in_string : unit -> bool β€” same shape: unit -> bool. Literally named in_string, no notes. πŸ¦‹
  • val is_keyword : string -> bool β€” string goes in, bool comes out.
  • val print_warnings : bool ref β€” a bool ref, so it's a mutable flag moment. πŸ”₯
  • val handle_docstrings : bool ref β€” another bool ref, same exact shape. 🌸
  • val comments : unit -> (string * Location.t) list β€” returns a list of (string * Location.t), exactly. πŸŽ€
  • val token_with_comments : Lexing.lexbuf -> Parser.token β€” Lexing.lexbuf to Parser.token, with the exact token_with_comments signature. ⭐
  • val set_preprocessor : (unit -> unit) -> ((Lexing.lexbuf -> Parser.token) -> Lexing.lexbuf -> Parser.token) -> unit β€” the long iconic one, with those exact function types and unit at the end. Slay. πŸ’…

okay that's the whole page, bestie. Footer cuteness, signed off: OCamldoc, 2026-06-22, Lexer(3). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from