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 so symbol_start and Parsing.symbol_end are 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, and symbol_end() returns the offset after the last character. The first character in a file is at offset 0. πŸŽ€
  • val symbol_end : unit -> int β€” see Parsing.symbol_start. That's the whole note, bestie. πŸ’–
  • val rhs_start : int -> int β€” same as Parsing.symbol_start and Parsing.symbol_end, but it returns the offset of the string matching the nth item on the right-hand side of the rule, where n is the integer parameter to rhs_start and rhs_end. And yes, n is 1 for the leftmost item. 🌈
  • val rhs_end : int -> int β€” see Parsing.rhs_start. Slay. πŸ’…
  • val symbol_start_pos : unit -> Lexing.position β€” same as symbol_start, but return a position instead of an offset. Iconic little upgrade. πŸ¦‹
  • val symbol_end_pos : unit -> Lexing.position β€” same as symbol_end, but return a position instead of an offset. Periodt. ⭐
  • val rhs_start_pos : int -> Lexing.position β€” same as rhs_start, but return a position instead of an offset. We love consistency. πŸ’œ
  • val rhs_end_pos : int -> Lexing.position β€” same as rhs_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 for ocamlyacc-generated parsers. After Parsing.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 false turns 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