keyword.mli 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(* This module provides some type and function definitions
   that help deal with the keywords that we recognize within
   semantic actions. *)

(* The user can request position information either at type
   [int] (a simple offset) or at type [Lexing.position]. *)

type flavor =
  | FlavorOffset
  | FlavorPosition

(* The user can request position information about the
   start or end of a symbol. *)

type where =
  | WhereStart
  | WhereEnd

(* The user can request position information about a production's
   left-hand side or about one of the symbols in its right-hand
Yann Régis-Gianas's avatar
Yann Régis-Gianas committed
21 22 23 24 25 26
   side, which he can refer to by position or by name.

   A positional reference of the form [$i] is a syntactic sugar for the
   name [_i]. This surface syntax is first parsed as a [parsed_subject]
   and desugared as a [subject] during keywords rewriting into actual
   OCaml identifiers. (See {!Lexer.transform_keywords}) *)
27 28 29 30
type parsed_subject =
  | PLeft
  | PRightDollar of int
  | PRightNamed of string
31

32
and subject =
33 34 35 36
  | Left
  | RightNamed of string

(* Keywords inside semantic actions. They allow access to semantic
Yann Régis-Gianas's avatar
Yann Régis-Gianas committed
37
   values or to position information.
38

Yann Régis-Gianas's avatar
Yann Régis-Gianas committed
39 40 41
   As said previously, a positional reference is a syntactic sugar
   which appears in a [parsed_keyword] but is desugared in the
   actual [keyword] representation. *)
42 43 44 45 46 47
type parsed_keyword =
  | PDollar of int
  | PPosition of parsed_subject * where * flavor
  | PSyntaxError

and keyword =
48 49 50 51 52 53 54 55 56
  | Position of subject * where * flavor
  | SyntaxError

(* This maps a [Position] keyword to the name of the variable that the
   keyword is replaced with. *)

val posvar: subject -> where -> flavor -> string

(* Sets of keywords. *)
57
module KeywordSet : Set.S with type elt = keyword
58