package lrgrep
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Detailed error messages for Menhir-generated parsers
Install
dune-project
Dependency
Authors
Maintainers
Sources
lrgrep-0.9.tbz
sha256=e53de12e4c5cbe6bca00643593266b4f9fa2e3f6a138195eeff7a4329f5c1c75
sha512=7fd7c4d11506fea7cc11c9bbf5aea9142d905643553c0c90e1bb16b794106b0c14a266acf89ae91b6929008dc0ba6515f788642873e2e4ba6c3d49bd45d25127
doc/kernel/Kernel/Codegen/index.html
Module Kernel.CodegenSource
Code generation for the LR matching machine
This module generates the OCaml code for the LR matching machine from the compiled specification and the generated automaton. The "machine" is translated to a sparse transition table, a bytecode program. An OCaml wrapper is generated to interpret the bytecode and invoke the appropriate semantic actions.
Main components:
- The
spectype holds global configuration including the parser name and lexer definition.
- The
output_header,output_trailerfunctions generate the outer module structure wrapping the generated code.
- The
output_rulefunction is the core code generation function that: - Outputs the bytecode and transition tables for the abstract machine
- Outputs semantic actions for each branch
- Outputs wrapper functions glueing the interpreter to user actions
Implementation details:
- The
output_tablefunction formats and outputs the already-compacted bytecode and transition table as an OCamlLrgrep_runtime.programrecord. The actual compaction is performed byLrgrep_support.compactinsideoutput_rulebeforeoutput_tableis called.
- The
output_execute_functiongenerates a case analysis matching on: - The clause number
- The lookahead token
- For each branch that accepts the clause, outputs a case that: 1. Binds registers to captured variables 2. Executes the semantic action 3. Returns the result
- The
bind_capturefunction handles different capture types: Value: Regular captured values with full type informationStart_loc,End_loc: Start/end position captures- It handles optional vs required captures based on whether they can be undefined
- The
lookahead_constraintfunction generates pattern matching for branches with lookahead constraints, ensuring only the right tokens trigger each branch.
- The
output_rulefunction proceeds in three steps: 1. Compacts the state machine viaLrgrep_support.compactand outputs the bytecode and transition tables 2. Generates semantic actions with proper variable binding, including type recovery for captured values 3. Outputs a wrapper function to glue the interpreter to user actions
Source
val output_table :
Utils.Code_printer.t ->
Syntax.rule ->
('g, 'r, 'a, 'b) Automata.Machine.t ->
(string * Lrgrep_support_packer.table * int array) ->
unitSource
val output_rule :
'g Info.grammar ->
spec ->
Syntax.rule ->
('g, 'r) Spec.clauses ->
('g, 'r) Spec.branches ->
('g, 'r, 'a, 'b) Automata.Machine.t ->
printer sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>