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* : **?keyword\_edition:(int * int) option * string list -&gt; 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**  
| 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**

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

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

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

*val is\_keyword* : **string -&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-23 OCamldoc

---

Document: Lexer(3o) from ocaml 5.5.2-r0 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
