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/Transl/index.html
Module Kernel.TranslSource
Translation from syntax to regular expressions
This module handles the translation of pattern syntax (from the grammar) into regular expression structures that can be processed by the compilation pipeline.
Main components:
- Indices module: Pre-computes many-to-many mappings between symbols and LR states:
by_incoming_symbol: Maps each symbol to the set of LR states that have a transition on that symbolprod_by_lhs: Maps each nonterminal to the set of productions that have it as LHSby_items: Maps each LR(0) item to the set of LR1 states that recognizes it
- Globbing module: Implements pattern globbing for filters, allowing patterns like `
foo _* bar` to match any sequence that starts with `foo`, ends with `bar`, with any symbols in between.
struct_filter: Parses a glob pattern into componentsnormalize_filter: Normalizes the parsed componentsextract: Given a right-hand side, finds the positions where the pattern matches
transl_filter: Translates filter patterns into sets of LR states that satisfy the filter.
transl: The main translation function that converts a regular expression from the syntax tree into an Expr.t regular expression structure.
Tricky implementation details:
- Globbing implements substring matching with optional wildcards (`_` for exact match, `.*` for skip). The
match_skipandextract_skipfunctions implement sophisticated backtracking to find all matching positions.
- The
compile_reduce_exprfunction uses the Redgraph.target_trie to find all states where a reduction can occur. It tracks both immediate reductions (can happen now) and deferred reductions (need to follow transitions first).
- The translation handles two modes:
- Regular mode: Normal parsing with captures
- Reduction mode: Used internally for nested reductions within reductions (which aren't allowed, hence the error)
- The
Usagesystem tracks which parser constructs are actually used, enabling dead-code analysis.
- Filters can match on the left-hand side (which production) and right-hand side (which sequence of symbols). The globbing system enables powerful pattern matching on the parse stack contents.
Source
val string_of_goto :
'a Kernel__Info.grammar ->
'a Kernel__Info.goto_transition Fix.Indexing.index ->
stringSource
val transl_filter :
'g Info.grammar ->
'g Indices.t ->
Stdlib.Lexing.position ->
lhs:Syntax.symbol option ->
rhs:(Syntax.filter_symbol * Stdlib.Lexing.position) list ->
'g Info.lr1 Utils.IndexSet.tSource
val compile_reduce_expr :
'g Info.grammar ->
'g Redgraph.graph ->
'g Redgraph.target_trie ->
'g Kernel__Regexp.Expr.t ->
'g Redgraph.target Utils.IndexSet.t * 'g Info.lr1 Utils.IndexSet.tSource
val transl :
'g Info.grammar ->
'g Redgraph.graph ->
'g Indices.t ->
'g Redgraph.target_trie ->
capture:
(Syntax.capture_kind ->
string ->
Kernel__Regexp.Capture.n Utils.IndexSet.element) ->
Syntax.regular_expr ->
Kernel__Regexp.Capture.n Utils.IndexSet.t * 'g Regexp.Expr.t sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>