OCAMLLEX(1)

πŸ“¦
version 5.5.0 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– OCAMLLEX(1) πŸ’–

okay so bestie, welcome to the ocamllex page β€” it lives in the General Commands Manual and it is literally the OCaml lexer generator. yes, THE one. ✨


πŸ¦‹ NAME πŸ¦‹

ocamllex β€” the OCaml lexer generator, no cap. πŸ‘‘


🌸 SYNOPSIS 🌸

ocamllex [ -o output-file ] [ -ml ] filename.mll

✨ DESCRIPTION ✨

so like. the ocamllex(1) command generates OCaml lexers out of a set of regular expressions that have semantic actions attached to them, in the style of lex(1). it's giving classic, it's giving vintage, we love her. πŸ’…

when you run ocamllex(1) on the input file lexer.mll, you get OCaml code for a lexical analyzer in the file lexer.ml. boom. that's the whole glow-up. πŸ”₯

that file defines one lexing function per entry point in the lexer definition, and those functions have the exact same names as the entry points, fr fr. a lexing function takes a lexer buffer as its argument, and it returns the semantic attribute of the corresponding entry point. that's it, that's the job. 🫢

lexer buffers are an abstract data type implemented in the standard library module Lexing. and the functions Lexing.from_channel, Lexing.from_string and Lexing.from_function create lexer buffers that read from an input channel, a character string, or any reading function, respectively. three lil besties, three lil sources of input. 🌈

and when you use this in conjunction with a parser generated by ocamlyacc(1), the semantic actions compute a value belonging to the type token defined by the generated parsing module. iconic collaboration honestly. πŸŽ€


πŸ’… OPTIONS πŸ’…

the ocamllex(1) command recognizes the following options, bestie, and we are going through every single one:

  • -ml β€” outputs code that does not use OCaml's built-in automata interpreter. instead, the automaton gets encoded by OCaml functions. this one is mainly useful for debugging ocamllex(1) β€” and using it for production lexers is not recommended. so like, cute for snooping, not for shipping. πŸ™ˆ
  • -o output-file β€” specify the name of the output file that ocamllex(1) produces. the default is the input file name, with its extension replaced by .ml. so you get a say in where it goes πŸ’–
  • -q β€” quiet mode. ocamllex(1) normally outputs informational messages to standard output, and they get suppressed if you use option -q. shy girl era. 🀫
  • -v or -version β€” print version string and exit. πŸ¦‹
  • -vnum β€” print short version number and exit. short and sweet. ⭐
  • -help or --help β€” display a short usage summary and exit. the tutorial, but tiny. 🌸

πŸ‘‘ SEE ALSO πŸ‘‘

  • ocamlyacc(1).
  • The OCaml user's manual, chapter "Lexer and parser generators".

ok that's the whole page, you ate it up, go generate some lexers πŸ’–

and that's a wrap, bestie β€” this was OCAMLLEX(1) from the General Commands Manual, and we are obsessed. mwah, bye πŸŽ€πŸ’œ

πŸ“¦ where this page comes from