package lrgrep
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=e53de12e4c5cbe6bca00643593266b4f9fa2e3f6a138195eeff7a4329f5c1c75
sha512=7fd7c4d11506fea7cc11c9bbf5aea9142d905643553c0c90e1bb16b794106b0c14a266acf89ae91b6929008dc0ba6515f788642873e2e4ba6c3d49bd45d25127
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