Parsing(3)
π NAME π
okay so bestie, welcome to Parsing(3) from the OCaml library β this is the page for the run-time library that backs parsers generated by ocamlyacc. It's giving parser-support main character energy, and we're gonna go through every single val, exception, and caveat together. π«Ά
π§ MODULE π§
The module is literally called Parsing. That's the whole vibe. β¨
β¨ DOCUMENTATION β¨
Module Parsing
: sig end
This is the run-time library for parsers generated by ocamlyacc. No cap. πΈ
val symbol_start : unit -> intβ okay sosymbol_startandParsing.symbol_endare to be called in the action part of a grammar rule only. They return the offset of the string that matches the left-hand side of the rule:symbol_start()returns the offset of the first character, andsymbol_end()returns the offset after the last character. The first character in a file is at offset0. πval symbol_end : unit -> intβ seeParsing.symbol_start. That's the whole note, bestie. πval rhs_start : int -> intβ same asParsing.symbol_startandParsing.symbol_end, but it returns the offset of the string matching thenth item on the right-hand side of the rule, wherenis the integer parameter torhs_startandrhs_end. And yes,nis1for the leftmost item. πval rhs_end : int -> intβ seeParsing.rhs_start. Slay. πval symbol_start_pos : unit -> Lexing.positionβ same assymbol_start, but return a position instead of an offset. Iconic little upgrade. π¦val symbol_end_pos : unit -> Lexing.positionβ same assymbol_end, but return a position instead of an offset. Periodt. βval rhs_start_pos : int -> Lexing.positionβ same asrhs_start, but return a position instead of an offset. We love consistency. πval rhs_end_pos : int -> Lexing.positionβ same asrhs_end, but return a position instead of an offset. Chef's kiss. πval clear_parser : unit -> unitβ this one empties the parser stack. Call it just after a parsing function has returned, to remove all pointers from the parser stack to structures that were built by semantic actions during parsing. It's optional, but it lowers the memory requirements of the programs. Lowkey a good cleanup bestie. π§exception Parse_errorβ raised when a parser encounters a syntax error. It can also be raised from the action part of a grammar rule, to initiate error recovery. So yeah, it's the dramatic gasp of parser errors. πval set_trace : bool -> boolβ controls debugging support forocamlyacc-generated parsers. AfterParsing.set_trace true, the pushdown automaton that executes the parsers prints a trace of its actions β reading a token, shifting a state, reducing by a rule β on standard output.Parsing.set_trace falseturns this debugging trace off. The boolean returned is the previous state of the trace flag. Since 3.11. π₯
tiny vibe check: all those val signatures are exactly what they look like β keep the names, types, and behavior as written, because parser internals do not play about correctness. π
mwah π this page was brought to you by OCamldoc, dated 2026-06-22, and it's the Parsing(3) page β 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