123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221(******************************************************************************)(* *)(* Menhir *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under *)(* the terms of the GNU Library General Public License version 2, with a *)(* special exception on linking, as described in the file LICENSE. *)(* *)(******************************************************************************)(**This module defines the data that is stored in .cmly files. *)(**In short, a .cmly file contains a value of type {!grammar}. *)(**The type definitions in this module are used in [Cmly_write], which
writes a .cmly file, and in {!Cmly_read}, which reads a .cmly file.
They should not be used anywhere else. *)(**All entities (terminal symbols, nonterminal symbols, and so on) are
represented as integers. These integers serve as indices into arrays.
This enables simple and efficient hashing, comparison, indexing, etc. *)typeterminal=inttypenonterminal=inttypeproduction=inttypelr0=inttypelr1=inttypeocamltype=stringtypeocamlexpr=stringtyperange={r_start:Lexing.position;r_end:Lexing.position;}type'alocated='a*rangetypeattribute={a_label:string;a_payload:string;a_position:range;}typeattributes=attributelisttypeterminal_def={t_name:string;t_kind:[`REGULAR|`ERROR|`EOF|`PSEUDO];t_type:ocamltypeoption;t_attributes:attributes;}typenonterminal_def={n_name:string;n_kind:[`REGULAR|`START];n_mangled_name:string;n_type:ocamltypeoption;n_positions:rangelist;n_nullable:bool;n_first:terminallist;n_attributes:attributes;}typesymbol=|Tofterminal|Nofnonterminaltypeidentifier=stringtypeaction={a_expr:ocamlexpr;a_keywords:Keyword.keywordlist;}type'symbolproducer_def='symbol*identifier*attributestypeproduction_def={p_kind:[`REGULAR|`START];p_lhs:nonterminal;p_rhs:symbolproducer_defarray;p_positions:rangelist;p_action:actionoption;p_attributes:attributes;(* Before 2023/08/02, these were the attributes of the left-hand
side of the production. Now, these are the attributes of the
production itself. *)}typelr0_state_def={lr0_incoming:symboloption;lr0_items:(production*int)list;}(**Detailed information on a state of the LR(1) automaton. *)typelr1_state_def={lr1_lr0:lr0;(**The LR(0) state that underlies this state. *)lr1_transitions:(symbol*lr1)list;(**The outgoing transitions of this state. Each outgoing transition
is represented as a pair of a label (a symbol) and a target state.
For each terminal symbol [t], there is at most one transition.
In deterministic mode (without --GLR), all shift/reduce conflicts are
eliminated, so, for each terminal symbol [t], there cannot be both a
transition and a reduction, and there is at most one reduction. *)lr1_reductions:(terminal*production)list;(**The reduction actions at this state. Each reduction action is
represented as a pair of a terminal symbol and a production.
In deterministic mode (without --GLR), all shift/reduce conflicts are
eliminated, so, for each terminal symbol [t], there cannot be both a
transition and a reduction, and there is at most one reduction. *)lr1_default_reduction:productionoption;(**This field is set to [Some prod] if this state reduces production [prod]
as a default reduction. Regardless of the value of this field, the above
fields are populated normally. *)}(* The surface syntax of a grammar, as found in the front-end.
A single set of type definitions is used to represent several variants of
the grammar, namely:
- the "higher" grammar,
before parameterized nonterminal symbols are expanded;
- the "ground" grammar,
after parameterized nonterminal symbols have been expanded,
but before %inline nonterminal symbols are eliminated.
The type parameter ['symbol] designates the symbols that appear in the
right-hand side of a production. In the higher grammar, it is [parameter];
in the ground grammar, it is [surface_symbol], that is, just a string.
The type parameter ['param] designates the parameters of a production.
In the higher grammar, it is [surface_symbol list], because a production
can be parameterized; it the ground grammar, it is [unit]. *)typesurface_symbol=stringtypetoken_associativity=|LeftAssoc|RightAssoc|NonAssoc|UndefinedAssoctypepriority_level={pl_input_file:string;pl_level:int;}type'symbolsurface_branch={br_position:range;br_producers:'symbolproducer_deflist;br_action:action;br_prec_annotation:surface_symbollocatedoption;br_production_level:priority_level;br_attributes:attributes;}type('param,'symbol)surface_rule={r_parameters:'param;r_branches:'symbolsurface_branchlist;r_inline:bool;r_positions:rangelist;r_public:bool;r_attributes:attributes;}typesurface_token={tk_ocamltype:ocamltypeoption;tk_position:range;tk_alias:stringoption;tk_attributes:attributes;tk_associativity:token_associativity;tk_precedence:priority_levellocatedoption;tk_is_declared:bool;}type('param,'symbol)surface_syntax={s_types:('symbol*ocamltype)list;s_tokens:(string*surface_token)list;s_rules:(string*('param,'symbol)surface_rule)list;}typeparameter=|ParameterVarofsurface_symbollocated|ParameterAppofsurface_symbollocated*parameterlist|ParameterAnonymousof(parametersurface_branch)listlocatedtypehigher_syntax=(surface_symbollist,parameter)surface_syntaxtypeground_syntax=(unit,surface_symbol)surface_syntax(* Record packing all information about a grammar *)typegrammar={g_basename:string;g_preludes:stringlist;g_postludes:stringlist;g_terminals:terminal_defarray;g_nonterminals:nonterminal_defarray;g_productions:production_defarray;g_lr0_states:lr0_state_defarray;g_lr1_states:lr1_state_defarray;g_start_symbols:stringlist;g_entry_points:(nonterminal*production*lr1)list;g_attributes:attributes;g_parameters:stringlist;g_on_error_reduce:(string*priority_level)list;g_before_expansion:higher_syntax;g_before_inlining:ground_syntax;}