Lexer(3) OCaml library Lexer(3)

# [NAME](#NAME)

Lexer - The lexical analyzer

# [Module](#Module)

Module Lexer

# [Documentation](#Documentation)

Module **Lexer**  
: **sig end**

The lexical analyzer

Warning: this module is unstable and part of **Compiler\_libs** .

*val init* : **unit -&gt; unit**

*val token* : **Lexing.lexbuf -&gt; Parser.token**

*val skip\_hash\_bang* : **Lexing.lexbuf -&gt; unit**

*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**  
| Invalid\_literal **of** **string**  
| Invalid\_directive **of** **string * string option**

*exception Error* **of** **error * Location.t**

*val in\_comment* : **unit -&gt; bool**

*val in\_string* : **unit -&gt; bool**

*val print\_warnings* : **bool ref**

*val handle\_docstrings* : **bool ref**

*val comments* : **unit -&gt; (string * Location.t) list**

*val token\_with\_comments* : **Lexing.lexbuf -&gt; Parser.token**

*val set\_preprocessor* : **(unit -&gt; unit) -&gt;** **((Lexing.lexbuf -&gt; Parser.token) -&gt;** **Lexing.lexbuf -&gt; Parser.token) -&gt;** **unit**

2026-10-27 OCamldoc

---

Document: Lexer(3o) from ocaml-4 4.14.4-r4 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
