Parse(3)
πΈ NAME πΈ
okay so bestie, you opened Parse(3) β the OCaml library page for Parse β and no cap, this is lowkey the parser's entry-point era. Compiler-libs girlie, unstable-core, main-character energy. π
π Module π
Module Parse : sig end
Entry points in the parser.
β οΈ Warning: this module is unstable and part of Compiler_libs. She's iconic, but she's not giving "stable API promise," so vibe-check before you commit. π
β¨ Documentation β¨
First up, the first batch of entry points, no notes:
val implementation : Lexing.lexbuf -> Parsetree.structureval interface : Lexing.lexbuf -> Parsetree.signatureval toplevel_phrase : Lexing.lexbuf -> Parsetree.toplevel_phraseval use_file : Lexing.lexbuf -> Parsetree.toplevel_phrase listval core_type : Lexing.lexbuf -> Parsetree.core_typeval expression : Lexing.lexbuf -> Parsetree.expressionval pattern : Lexing.lexbuf -> Parsetree.patternval module_type : Lexing.lexbuf -> Parsetree.module_typeval module_expr : Lexing.lexbuf -> Parsetree.module_expr
The functions below can be used to parse Longident safely. π«Ά
val longident : Lexing.lexbuf -> Longident.tβ okay solongidentis guaranteed to parse all subclasses ofLongident.tused in OCaml: values, constructors, simple or extended module paths, and types or module types. BUT plot twist: this function accepts inputs which are not accepted by the compiler, because they combine functor applications and infix operators. In valid OCaml syntax, only value-level identifiers may end with infix operatorsFoo.( + ). Moreover, in value-level identifiers the module pathFoomust be simple (M.Nrather thanF(X)): functor applications may only appear in type-level identifiers. As a consequence, a path such asF(X).( + )is not a valid OCaml identifier; but it is accepted by this function. π
The next functions are specialized to a subclass of Longident.t. π
val val_ident : Lexing.lexbuf -> Longident.tβ this function parses a syntactically valid path for a value. For instance,x,M.x, and(+.)are valid. Contrarily,M.A,F(X).x, andtrueare rejected.Longidentfor OCaml's value cannot contain functor application. The last component of theLongident.tis not capitalized, but can be an operatorA.Path.To.(.%.%.(;..)<-). πval constr_ident : Lexing.lexbuf -> Longident.tβ this function parses a syntactically valid path for a variant constructor. For instance,A,M.AandM.(::)are valid, but bothM.aandF(X).Aare rejected.Longidentfor OCaml's variant constructors cannot contain functor application. The last component of theLongident.tis capitalized, or it may be one of the special constructors:true,false,(),[],(::). Among those special constructors, only(::)can be prefixed by a module path (A.B.C.(::)). β¨val simple_module_path : Lexing.lexbuf -> Longident.tβ this function parses a syntactically valid path for a module. For instance,A, andM.Aare valid, but bothM.aandF(X).Aare rejected.Longidentfor OCaml's module cannot contain functor application. The last component of theLongident.tis capitalized. π§val extended_module_path : Lexing.lexbuf -> Longident.tβ this function parse syntactically valid path for an extended module. For instance,A.BandF(A).Bare valid. Contrarily,(.%())or[]are both rejected. The last component of theLongident.tis capitalized. πval type_ident : Lexing.lexbuf -> Longident.tβ this function parse syntactically valid path for a type or a module type. For instance,A,t,M.tandF(X).tare valid. Contrarily,(.%())or[]are both rejected. In path for type and module types, only operators and special constructors are rejected. π
mwah π β this cutie page is from OCamldoc, dated 2026-06-22, and it's literally Parse(3). periodt. π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms