package lrgrep
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=84a1874d0c063da371e19c84243aac7c40bfcb9aaf204251e0eb0d1f077f2cde
sha512=5a16ff42a196fd741bc64a1bdd45b4dca0098633e73aa665829a44625ec15382891c3643fa210dbe3704336eab095d4024e093e37ae5313810f6754de6119d55
doc/syntax/Syntax/index.html
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.
Kind of quantifier used in regular expressions.
This represents a piece of OCaml code, as appearing in semantic actions, as well as in the header and trailer.
type symbol = | Name of string(*Symbols are usually simple names, like 'a' or 'X'.
*)| 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)
Symbols used in filter globbing expressions to specify matching criteria.
regular_desc describes the different cases of the regular expression syntax.
type regular_desc = | Atom of string option * wild_symbol * Utils.Usage.mark(*
*)Atom (capture, sym,_)represents the base cases (symboland_).| Alternative of regular_expr list(*A disjunction of multiple expressions.
*)e1 | e2 | e3is represented asAlternative [e1; e2; e3]| Repetition of {expr : regular_expr;policy : quantifier_kind;
}(*
*)Repetition erepresentse*ande**| Reduce of {capture : string option;mark : Utils.Usage.mark;expr : regular_expr;policy : quantifier_kind;
}(*
*)Reduce {expr; _}represents[expr]and[[expr]].| Concat of regular_expr list(*
*)Concat [e1; e2; ..]ise1; e2; ...| Filter of filter(*
*)Filter frepresents/foo: bar...
and regular_expr = {desc : regular_desc;position : position;(*the position where this term ends
*)
}regular_expr adds position information to regular_desc for error reporting purposes.
type clause_action = | Total of ocaml_code(*...
*)code, normal semantic action *| Partial of ocaml_code(*... partial
*)..., a semantic action that can returnNoneto continue matching| Unreachable of position(*
*)... { . }the pattern should never match
The semantic action associated to a pattern
type pattern = {expr : regular_expr;(*the pattern
*)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.
A clause is a pair of a pattern and an action, representing one rule.
type rule = {name : string;(*Name of the rule
*)error : bool * position;(*
*)erroris true if this entry only matches failing stacks. Syntactically, an error entry has the form: rule x ... = parse error | ...startsymbols : (string * position) list;(*The list of entrypoints to support, or for all entrypoints.
*)args : string list;(*The list of OCaml arguments to abstract over, e.g the
*)x yinrule foo x y = ...clauses : clause_group list;(*The list of clauses to match
*)
}A rule in .lrgrep file is represented by the rule type.
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
Convert a location to a Cmon record.
Convert an OCaml code to a Cmon tuple.
Convert a function and a position to a Cmon pair.
Convert an option to a Cmon value.
Convert a capture to a Cmon value.
Convert a filter symbol to a Cmon value.
Convert a regular expression to a Cmon value.
Convert a clause action to a Cmon value.
Convert a lexer definition to a Cmon value.
The role of a captured value in a regular expression: captures only the start or end location, captures the value (and its location)
Print position for error or warning messages
val warn :
Stdlib.Lexing.position ->
('a, Stdlib.out_channel, unit, unit) Stdlib.format4 ->
'aReport a warning
Report an error
val nonfatal_error :
Stdlib.Lexing.position ->
('a, Stdlib.out_channel, unit, unit) Stdlib.format4 ->
'a