Commit df76527b authored by POTTIER Francois's avatar POTTIER Francois

Remove [Positions] from the .cmly API.

parent 34d90977
......@@ -29,12 +29,18 @@ module type GRAMMAR = sig
type ocamltype = string
type ocamlexpr = string
module Range : sig
type t
val startp: t -> Lexing.position
val endp: t -> Lexing.position
end
module Attribute : sig
type t
val label : t -> string
val has_label : string -> t -> bool
val payload : t -> string
val position : t -> Positions.t
val position : t -> Range.t
end
module Grammar : sig
......@@ -58,7 +64,7 @@ module type GRAMMAR = sig
val mangled_name : t -> string
val kind : t -> [`REGULAR | `START]
val typ : t -> ocamltype option
val positions : t -> Positions.t list
val positions : t -> Range.t list
val nullable : t -> bool
val first : t -> terminal list
val attributes : t -> Attribute.t list
......@@ -83,7 +89,7 @@ module type GRAMMAR = sig
val kind : t -> [`REGULAR | `START]
val lhs : t -> nonterminal
val rhs : t -> (symbol * identifier * Attribute.t list) array
val positions : t -> Positions.t list
val positions : t -> Range.t list
val action : t -> Action.t option
val attributes : t -> Attribute.t list
end
......
......@@ -18,10 +18,15 @@ type lr1 = int
type ocamltype = string
type ocamlexpr = string
type range = {
r_start: Lexing.position;
r_end: Lexing.position;
}
type attribute = {
a_label: string;
a_payload: string;
a_position: Positions.t;
a_position: range;
}
type attributes =
......@@ -39,7 +44,7 @@ type nonterminal_def = {
n_kind: [`REGULAR | `START];
n_mangled_name: string;
n_type: ocamltype option;
n_positions: Positions.t list;
n_positions: range list;
n_nullable: bool;
n_first: terminal list;
n_attributes: attributes;
......@@ -63,7 +68,7 @@ type production_def = {
p_kind: [`REGULAR | `START];
p_lhs: nonterminal;
p_rhs: producer_def array;
p_positions: Positions.t list;
p_positions: range list;
p_action: action option;
p_attributes: attributes;
}
......
......@@ -83,6 +83,19 @@ module Make (G : sig val grammar : grammar end) : GRAMMAR = struct
type ocamltype = string
type ocamlexpr = string
module Range = struct
type t =
Cmly_format.range
let startp range =
range.r_start
let endp range =
range.r_end
end
module Attribute = struct
type t =
......
......@@ -18,11 +18,20 @@ let ocamltype (typo : Stretch.ocamltype option) : ocamltype option =
| Some typ ->
Some (ocamltype typ)
let range (pos : Positions.t) : range =
{
r_start = Positions.start_of_position pos;
r_end = Positions.end_of_position pos;
}
let ranges =
List.map range
let attribute (label, payload : Syntax.attribute) : attribute =
{
a_label = Positions.value label;
a_payload = raw_content payload;
a_position = Positions.position label;
a_position = range (Positions.position label);
}
let attributes : Syntax.attributes -> attributes =
......@@ -55,7 +64,7 @@ let nonterminal (nt : Nonterminal.t) : nonterminal_def =
n_name = Nonterminal.print false nt;
n_mangled_name = Nonterminal.print true nt;
n_type = if is_start then None else ocamltype (Nonterminal.ocamltype nt);
n_positions = if is_start then [] else Nonterminal.positions nt;
n_positions = if is_start then [] else ranges (Nonterminal.positions nt);
n_nullable = Analysis.nullable nt;
n_first = List.map Terminal.t2i (TerminalSet.elements (Analysis.first nt));
n_attributes = if is_start then [] else attributes (Nonterminal.attributes nt);
......@@ -88,7 +97,7 @@ let production (prod : Production.index) : production_def =
p_kind = if Production.is_start prod then `START else `REGULAR;
p_lhs = Nonterminal.n2i (Production.nt prod);
p_rhs = rhs prod;
p_positions = Production.positions prod;
p_positions = ranges (Production.positions prod);
p_action = if Production.is_start prod then None
else Some (action (Production.action prod));
p_attributes = attributes (Production.lhs_attributes prod);
......
# This is the list of modules that must go into MenhirSdk.
Keyword
Positions
IO
Version
Cmly_format
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment