package lrgrep

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Kernel.SpecSource

Specification interface

This module exports the data structures that represent the user's error specification after parsing and resolution.

Type definitions:

  • ('g, 'r) clause: A group of patterns sharing the same action (one clause in the grammar)
  • ('g, 'r) branch: A single pattern within a clause
  • clause_def: Additional metadata about a clause, mainly for handling %shortest groups:
  • shortest: Is the clause in a %shortest group
  • new_group: Is the clause the first of the group? If true, it starts a new priority group.
  • ('g, 'r) clauses: All clauses in a rule:
  • definitions: The clause definition for each clause
  • captures: The captured variables for each clause
  • ('g, 'r) branches: All branches across all clauses:
  • clause, pattern, expr: Branch properties. Pattern is the abstract syntax of the pattern being recognized, while expr is a lower-level representation of the pattern as a regular expression.
  • of_clause: Mapping from clauses to their branches
  • lookaheads: Optional lookahead constraints per branch
  • br_captures: Captured variables per branch
  • is_total, is_partial: Whether branches are total/partial
  • priority: Priorities determine which branch should match when multiple branches succeed. Text order is used most of the time (first branch matches first), except for a %shortest group, in which case the branch that matches the first has the priority.
  • 'g _rule: A rule with all its clauses and branches

Main functions:

  • branch_count: Return the number of branches
  • import_rule: Compile a Syntax.rule into the internal specification

Implementation details:

  • The priority system allows specification of multiple clauses with different precedence. Later clauses have lower priority.
  • The is_total / is_partial distinction matters for coverage analysis: partial clauses only accept specific lookaheads, total clauses accept any lookahead.
  • The import_rule function handles various clause types:
  • Normal clauses (total)
  • Partial clauses with specific lookahead constraints
  • %shortest groups where all clauses share priority

TODO: "Unreachable" clauses are not implemented at the moment.

Sourcetype ('g, 'r) clause
Sourcetype ('g, 'r) branch
Sourcetype clause_def = {
  1. new_group : bool;
  2. shortest : bool;
  3. syntax : Syntax.clause;
}
Sourcetype ('g, 'r) clauses = {
  1. definitions : (('g, 'r) clause, clause_def) Fix.Indexing.vector;
  2. captures : (('g, 'r) clause, (Regexp.Capture.n, Syntax.capture_kind * string) Utils.Misc.indexmap) Fix.Indexing.vector;
}
Sourcetype ('g, 'r) branches = {
  1. clause : (('g, 'r) branch, ('g, 'r) clause Fix.Indexing.index) Fix.Indexing.vector;
  2. pattern : (('g, 'r) branch, Syntax.pattern) Fix.Indexing.vector;
  3. expr : (('g, 'r) branch, 'g Regexp.Expr.t) Fix.Indexing.vector;
  4. of_clause : (('g, 'r) clause, ('g, 'r) branch Utils.Misc.indexset) Fix.Indexing.vector;
  5. lookaheads : (('g, 'r) branch, 'g Info.terminal Utils.Misc.indexset option) Fix.Indexing.vector;
  6. br_captures : (('g, 'r) branch, Regexp.Capture.n Utils.Misc.indexset) Fix.Indexing.vector;
  7. is_total : ('g, 'r) branch Utils.Boolvector.t;
  8. is_partial : ('g, 'r) branch Utils.Boolvector.t;
  9. priority : (('g, 'r) branch, ('g, 'r) branch Fix.Indexing.opt Fix.Indexing.index) Fix.Indexing.vector;
}
Sourceval branch_count : ('g, 'r) branches -> ('g, 'r) branch Fix.Indexing.cardinal
Sourcetype 'g _rule =
  1. | Rule : ('g, 'r) clauses * ('g, 'r) branches -> 'g _rule