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:

  • Int and Float β€” for integer and floating-point numbers πŸ”’
  • String β€” for string literals, enclosed in double quotes
  • Char β€” for character literals, enclosed in single quotes
  • Ident β€” 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 s is returned as Kwd s if s belongs to this list, and as Ident s otherwise. ✨
  • A special character s is returned as Kwd s if s belongs to this list, and cause a lexical error (exception Stream.Error with 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