package lrgrep

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

Module SyntaxSource

The shallow abstract syntax

This module defines the shallow abstract syntax for an error specification file (.lrgrep). It includes types for representing locations, symbols, regular expressions, semantic actions, and the overall structure of a lexer definition.

Sourcetype quantifier_kind =
  1. | Longest
  2. | Shortest

Kind of quantifier used in regular expressions.

Sourcetype position = Stdlib.Lexing.position
Sourcetype ocaml_code = position * string

This represents a piece of OCaml code, as appearing in semantic actions, as well as in the header and trailer.

Sourcetype symbol =
  1. | Name of string
    (*

    Symbols are usually simple names, like 'a' or 'X'.

    *)
  2. | Apply of string * symbol list
    (*

    Menhir supports higher-order non-terminals. In this case, a symbol is the application of the higher-order non-terminal to some arguments. E.g separated_list(sep, X) is represented as: Apply ("separated_list", [Name "sep"; Name "X"])

    *)

A grammar symbol (a terminal or a non-terminal)

Sourcetype wild_symbol = symbol option

A wildcard symbol is either a symbol or '_'.

Sourcetype filter_symbol =
  1. | Skip
  2. | Find of wild_symbol
  3. | Dot

Symbols used in filter globbing expressions to specify matching criteria.

regular_desc describes the different cases of the regular expression syntax.

Sourcetype regular_desc =
  1. | Atom of string option * wild_symbol * Utils.Usage.mark
    (*

    Atom (capture, sym,_) represents the base cases (symbol and _).

    *)
  2. | Alternative of regular_expr list
    (*

    A disjunction of multiple expressions. e1 | e2 | e3 is represented as Alternative [e1; e2; e3]

    *)
  3. | Repetition of {
    1. expr : regular_expr;
    2. policy : quantifier_kind;
    }
    (*

    Repetition e represents e* and e**

    *)
  4. | Reduce of {
    1. capture : string option;
    2. mark : Utils.Usage.mark;
    3. expr : regular_expr;
    4. policy : quantifier_kind;
    }
    (*

    Reduce {expr; _} represents [expr] and [[expr]].

    *)
  5. | Concat of regular_expr list
    (*

    Concat [e1; e2; ..] is e1; e2; ...

    *)
  6. | Filter of filter
    (*

    Filter f represents /foo: bar...

    *)
Sourceand regular_expr = {
  1. desc : regular_desc;
  2. position : position;
    (*

    the position where this term ends

    *)
}

regular_expr adds position information to regular_desc for error reporting purposes.

Sourceand filter = {
  1. lhs : wild_symbol option;
  2. rhs : (filter_symbol * position) list;
}
Sourcetype clause_action =
  1. | Total of ocaml_code
    (*

    ... code , normal semantic action *

    *)
  2. | Partial of ocaml_code
    (*

    ... partial ... , a semantic action that can return None to continue matching

    *)
  3. | Unreachable of position
    (*

    ... { . } the pattern should never match

    *)

The semantic action associated to a pattern

Sourcetype pattern = {
  1. expr : regular_expr;
    (*

    the pattern

    *)
  2. lookaheads : (symbol * position) list;
    (*

    restrict matching to these lookahead terminals, or for all terminals

    *)
}

A pattern is a combination of a regular expression and an optional list of lookahead constraints.

Sourcetype clause = {
  1. patterns : pattern list;
  2. action : clause_action;
    (*

    the semantic action

    *)
}

A clause is a pair of a pattern and an action, representing one rule.

Sourcetype clause_group = clause list
Sourcetype rule = {
  1. name : string;
    (*

    Name of the rule

    *)
  2. error : bool * position;
    (*

    error is true if this entry only matches failing stacks. Syntactically, an error entry has the form: rule x ... = parse error | ...

    *)
  3. startsymbols : (string * position) list;
    (*

    The list of entrypoints to support, or for all entrypoints.

    *)
  4. args : string list;
    (*

    The list of OCaml arguments to abstract over, e.g the x y in rule foo x y = ...

    *)
  5. clauses : clause_group list;
    (*

    The list of clauses to match

    *)
}

A rule in .lrgrep file is represented by the rule type.

Sourcetype lexer_definition = {
  1. header : ocaml_code;
  2. rules : rule list;
  3. trailer : ocaml_code;
}

An .lrgrep file is an header containing some OCaml code, one or more entries, and a trailer with some other OCaml code.

Helper and cmoning functions

Sourceval cmon_position : Stdlib.Lexing.position -> Cmon.t

Convert a location to a Cmon record.

Sourceval cmon_ocamlcode : (Stdlib.Lexing.position * string) -> Cmon.t

Convert an OCaml code to a Cmon tuple.

Sourceval cmon_positioned : ('a -> Cmon.t) -> ('a * Stdlib.Lexing.position) -> Cmon.t

Convert a function and a position to a Cmon pair.

Sourceval cmon_option : ('a -> Cmon.t) -> 'a option -> Cmon.t

Convert an option to a Cmon value.

Sourceval cmon_symbol : symbol -> Cmon.t

Convert a symbol to a Cmon value.

Sourceval cmon_capture : string option -> Cmon.t

Convert a capture to a Cmon value.

Sourceval cmon_wild_symbol : symbol option -> Cmon.t

Convert a wildcard symbol to a Cmon value.

Sourceval cmon_filter_symbol : filter_symbol -> Cmon.t

Convert a filter symbol to a Cmon value.

Sourceval cmon_quantifier_kind : quantifier_kind -> Cmon.t
Sourceval cmon_usage_mark : 'a -> Cmon.t
Sourceval cmon_regular_term : regular_desc -> Cmon.t
Sourceval cmon_regular_expression : regular_expr -> Cmon.t

Convert a regular expression to a Cmon value.

Sourceval cmon_clause_action : clause_action -> Cmon.t

Convert a clause action to a Cmon value.

Sourceval cmon_pattern : pattern -> Cmon.t

Convert a pattern to a Cmon value.

Sourceval cmon_clause : clause -> Cmon.t

Convert a clause to a Cmon value.

Sourceval cmon_rule : rule -> Cmon.t

Convert a rule to a Cmon value.

Sourceval cmon_definition : lexer_definition -> Cmon.t

Convert a lexer definition to a Cmon value.

Sourcetype capture_kind =
  1. | Start_loc
  2. | End_loc
  3. | Value

The role of a captured value in a regular expression: captures only the start or end location, captures the value (and its location)

Sourceval gnu_position : Stdlib.Lexing.position -> string

Print position for error or warning messages

Sourceval warn : Stdlib.Lexing.position -> ('a, Stdlib.out_channel, unit, unit) Stdlib.format4 -> 'a

Report a warning

Sourceval error : Stdlib.Lexing.position -> ('a, Stdlib.out_channel, unit, 'b) Stdlib.format4 -> 'a

Report an error

Sourceval nonfatal_error : Stdlib.Lexing.position -> ('a, Stdlib.out_channel, unit, unit) Stdlib.format4 -> 'a