Stdlib.Genlex(3)
π NAME π
Stdlib.Genlex β bestie, there is literally no description here, the manpage just says "no description" and honestly? iconic minimalism. π
(It's the OCaml stdlib's general-purpose lexer module, iykyk.)
This page lives in the OCaml library manual. π¦
π MODULE π
Module Stdlib.Genlex
β¨ DOCUMENTATION β¨
Module Genlex is a submodule of (module Stdlib__Genlex) β so it's part of the standard library gang, no extra install needed. π«Ά
π the token type
type token =
| Kwd of string
| Ident of string
| Int of int
| Float of float
| String of string
| Char of char
okay so this is the type of tokens, periodt. π The lexical classes are literally right here:
IntandFloatβ for integer and floating-point numbers π’Stringβ for string literals, enclosed in double quotesCharβ for character literals, enclosed in single quotesIdentβ for identifiers (either sequences of letters, digits, underscores and quotes, or sequences of 'operator characters' such as+,*, etc)Kwdβ for keywords (either identifiers or single 'special characters' such as(,}, etc)
π§ make_lexer
val make_lexer : string list -> char Stream.t -> token Stream.t
Construct the lexer function, bestie β this is the main character of the whole module π
The first argument is the list of keywords. Here's the tea on how it behaves:
- An identifier
sis returned asKwd sifsbelongs to this list, and asIdent sotherwise. β¨ - A special character
sis returned asKwd sifsbelongs to this list, and cause a lexical error (exceptionStream.Errorwith the offending lexeme as its parameter) otherwise. π so if you forget to list your special char, boom, error.
Blanks and newlines are skipped. πΈ Comments delimited by (* and *) are skipped as well, and can be nested β yes bestie, nested, we love a recursive comment situation π
A Stream.Failure exception is raised if end of stream is unexpectedly reached. so watch out for that π
and that's the whole page, no cap. stay slay, lex responsibly π
sign-off szn: this was brought to you by OCamldoc, version dated 2026-09-24, serving you Stdlib.Genlex(3) πβ¨ mwah π
π¦ where this page comes from
- alpine 3.24: ocaml-doc 4.14.4-r0 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms