syntax.mli 3.21 KB
Newer Older
1 2 3 4 5 6 7 8
(* Terminals and nonterminal symbols are strings. Identifiers
   (which are used to refer to a symbol's semantic value) are
   strings. A file name is a string. *)

type terminal =
    string

type nonterminal =
9
    string
10 11

type symbol =
12
    string
13

14 15
type identifier =
    string
16

17
type filename =
18 19
    string

20
(* A trailer is a source file fragment. *)
21 22

type trailer =
23
    Stretch.t
24

25
(* OCaml semantic actions are represented as stretches. *)
26 27 28 29

type action =
    Action.t

30 31
type token_associativity =
    LeftAssoc
32 33 34 35
  | RightAssoc
  | NonAssoc
  | UndefinedAssoc

36 37
type precedence_level =
    UndefinedPrecedence
38 39 40 41 42 43

  (* Items are incomparable when they originate in different files. A
     brand of type [Mark.t] is used to record an item's origin. The
     positions allow locating certain warnings. *)

  | PrecedenceLevel of Mark.t * int * Lexing.position * Lexing.position
44

45 46
type token_properties =
    {
47 48 49
               tk_filename      : filename;
               tk_ocamltype     : Stretch.ocamltype option;
               tk_position      : Positions.t;
50
      mutable  tk_associativity : token_associativity;
51
      mutable  tk_precedence    : precedence_level;
52
      mutable  tk_is_declared   : bool;
53 54
    }

55
type parameter =
56 57 58
  | ParameterVar of symbol Positions.located
  | ParameterApp of symbol Positions.located * parameters

59
and parameters =
60 61 62 63
    parameter list

type declaration =

64
    (* Raw OCaml code. *)
65 66 67

  | DCode of Stretch.t

68
    (* Raw OCaml functor parameter. *)
69 70 71 72 73 74 75 76 77

  | DParameter of Stretch.ocamltype (* really a stretch *)

    (* Terminal symbol (token) declaration. *)

  | DToken of Stretch.ocamltype option * terminal

    (* Start symbol declaration. *)

78
  | DStart of nonterminal
79 80 81 82 83 84 85 86 87

    (* Priority and associativity declaration. *)

  | DTokenProperties of terminal * token_associativity * precedence_level

    (* Type declaration. *)

  | DType of Stretch.ocamltype * parameter

88 89 90 91
    (* On-error-reduce declaration. *)

  | DOnErrorReduce of parameter

92
(* A [%prec] annotation is optional. A production can carry at most one.
93
   If there is one, it is a symbol name. See [ParserAux]. *)
94 95

type branch_prec_annotation =
96 97
    symbol Positions.located option

98 99 100 101
(* A "production level" is used to solve reduce/reduce conflicts. It reflects
   which production appears first in the grammar. See [ParserAux]. *)

type branch_production_level =
102
  | ProductionLevel of Mark.t * int
103 104

type producer =
105
    identifier Positions.located * parameter
106 107

type parameterized_branch =
108
    {
109 110
      pr_branch_position           : Positions.t;
      pr_producers                 : producer list;
111
      pr_action                    : action;
112
      pr_branch_prec_annotation    : branch_prec_annotation;
113
      pr_branch_production_level   : branch_production_level
114 115 116 117
    }

type parameterized_rule =
    {
118 119 120 121 122 123
      pr_public_flag       : bool;
      pr_inline_flag       : bool;
      pr_nt                : nonterminal;
      pr_positions         : Positions.t list;
      pr_parameters        : symbol list;
      pr_branches          : parameterized_branch list;
124 125
    }

126 127 128 129 130 131 132
type grammar =
    {
      pg_filename          : filename;
      pg_declarations      : declaration Positions.located list;
      pg_rules             : parameterized_rule list;
      pg_trailer           : trailer option;
    }