aboutsummaryrefslogtreecommitdiff
path: root/lib/syntax/S.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/syntax/S.ml')
-rw-r--r--lib/syntax/S.ml71
1 files changed, 50 insertions, 21 deletions
diff --git a/lib/syntax/S.ml b/lib/syntax/S.ml
index 710eb59..b52365d 100644
--- a/lib/syntax/S.ml
+++ b/lib/syntax/S.ml
@@ -13,7 +13,7 @@
*)
-type 'a repr = Report.t list -> 'a * Report.t list
+type 'a repr = Report.t list -> 'a
type pos = Lexing.position * Lexing.position
(** Starting and ending position for the given location *)
@@ -34,23 +34,23 @@ module type Expression = sig
type t'
(** External type used outside of the module *)
- val v : t * Report.t list -> t' * Report.t list
- val ident : (pos, t repr) variable -> t repr
+ val v : t -> t' * Report.t list
+ val ident : (pos, t) variable -> t
(*
Basic values, text, number…
*)
- val integer : pos -> string -> t repr
- val literal : pos -> string -> t repr
+ val integer : pos -> string -> t
+ val literal : pos -> string -> t
- val function_ : pos -> T.function_ -> t repr list -> t repr
+ val function_ : pos -> T.function_ -> t list -> t
(** Call a function. The functions list is hardcoded in lib/lexer.mll *)
- val uoperator : pos -> T.uoperator -> t repr -> t repr
+ val uoperator : pos -> T.uoperator -> t -> t
(** Unary operator like [-123] or [+'Text']*)
- val boperator : pos -> T.boperator -> t repr -> t repr -> t repr
+ val boperator : pos -> T.boperator -> t -> t -> t
(** Binary operator, for a comparaison, or an operation *)
end
@@ -61,7 +61,7 @@ module type Instruction = sig
type t'
(** External type used outside of the module *)
- val v : t * Report.t list -> t' * Report.t list
+ val v : t -> t' * Report.t list
type expression
@@ -98,17 +98,25 @@ module type Location = sig
type t
type instruction
- val location : pos -> instruction repr list -> t repr
+ val location : pos -> instruction list -> (t * Report.t list) repr
end
module type Analyzer = sig
module Expression : Expression
- module Instruction : Instruction with type expression = Expression.t' repr
- module Location : Location with type instruction = Instruction.t'
+
+ module Instruction :
+ Instruction with type expression = Expression.t' * Report.t list
+
+ module Location :
+ Location with type instruction = (Instruction.t' * Report.t list) repr
end
(** Helper module used in order to convert elements from the differents
- representation levels *)
+ representation levels.
+
+ Thoses functions are intended to be used in the menhir parser, in order to
+ limit the code in the mly file.
+*)
module Helper (E : sig
type t
(** Internal type used in the evaluation *)
@@ -116,18 +124,39 @@ module Helper (E : sig
type t'
(** External type used outside of the module *)
- val v : t * Report.t list -> t' * Report.t list
+ val v : t -> t' * Report.t list
end) : sig
- val v : E.t repr -> E.t' repr
+ val v : E.t repr -> Report.t list -> E.t' * Report.t list
+ (** Convert an instruction from the internal representation *)
+
+ val v' : E.t -> E.t' * Report.t list
+ (** Convert an expression from the internal representation *)
- val variable : (pos, E.t repr) variable -> (pos, E.t' repr) variable
+ val variable :
+ (pos, E.t) variable -> (pos, Report.t list -> E.t' * Report.t list) variable
+
+ val variable' : (pos, E.t) variable -> (pos, E.t' * Report.t list) variable
(** Convert a variable from the [Expression.t] into [Expression.t'] *)
end = struct
- let v : E.t repr -> E.t' repr =
+ let v : E.t repr -> Report.t list -> E.t' * Report.t list =
fun v report ->
- let value, report = v report in
- E.v (value, report)
+ let value = v report in
+ E.v value
+
+ let v' : E.t -> E.t' * Report.t list = fun v -> E.v v
+
+ let variable :
+ (pos, E.t) variable ->
+ (pos, Report.t list -> E.t' * Report.t list) variable =
+ fun variable ->
+ let v' : E.t -> Report.t list -> E.t' * Report.t list =
+ fun t report ->
+ ignore report;
+ E.v t
+ in
+
+ { variable with index = Option.map v' variable.index }
- let variable : (pos, E.t repr) variable -> (pos, E.t' repr) variable =
- fun variable -> { variable with index = Option.map v variable.index }
+ let variable' : (pos, E.t) variable -> (pos, E.t' * Report.t list) variable =
+ fun variable -> { variable with index = Option.map v' variable.index }
end