From 319c1e4474f4fefde688720b78e8abf315513a32 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Wed, 25 Oct 2023 18:41:27 +0200 Subject: Now I have the API I want. Everything is abstract in the type S.Analyzer --- lib/syntax/S.ml | 70 +++++++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 52 deletions(-) (limited to 'lib/syntax/S.ml') diff --git a/lib/syntax/S.ml b/lib/syntax/S.ml index b52365d..4a6b3e2 100644 --- a/lib/syntax/S.ml +++ b/lib/syntax/S.ml @@ -13,8 +13,6 @@ *) -type 'a repr = Report.t list -> 'a - type pos = Lexing.position * Lexing.position (** Starting and ending position for the given location *) @@ -24,7 +22,7 @@ type ('a, 'b) variable = { pos : 'a; name : string; index : 'b option } If missing, the index should be considered as [0].*) -type ('a, 'b) clause = pos * 'a * 'b repr list +type ('a, 'b) clause = pos * 'a * 'b list (** Represent the evaluation over an expression *) module type Expression = sig @@ -34,7 +32,7 @@ module type Expression = sig type t' (** External type used outside of the module *) - val v : t -> t' * Report.t list + val v : t -> t' val ident : (pos, t) variable -> t (* @@ -61,54 +59,50 @@ module type Instruction = sig type t' (** External type used outside of the module *) - val v : t -> t' * Report.t list + val v : t -> t' type expression - val call : pos -> T.keywords -> expression list -> t repr + val call : pos -> T.keywords -> expression list -> t (** Call for an instruction like [GT] or [*CLR] *) - val location : pos -> string -> t repr + val location : pos -> string -> t (** Label for a loop *) - val comment : pos -> t repr + val comment : pos -> t (** Comment *) - val expression : expression -> t repr + val expression : expression -> t (** Raw expression *) val if_ : pos -> (expression, t) clause -> elifs:(expression, t) clause list -> - else_:(pos * t repr list) option -> - t repr + else_:(pos * t list) option -> + t - val act : pos -> label:expression -> t repr list -> t repr + val act : pos -> label:expression -> t list -> t val assign : pos -> (pos, expression) variable -> T.assignation_operator -> expression -> - t repr + t end module type Location = sig type t type instruction - val location : pos -> instruction list -> (t * Report.t list) repr + val location : pos -> instruction list -> t * Report.t list end module type Analyzer = sig module Expression : Expression - - module Instruction : - Instruction with type expression = Expression.t' * Report.t list - - module Location : - Location with type instruction = (Instruction.t' * Report.t list) repr + module Instruction : Instruction with type expression = Expression.t' + module Location : Location with type instruction = Instruction.t' end (** Helper module used in order to convert elements from the differents @@ -124,39 +118,11 @@ module Helper (E : sig type t' (** External type used outside of the module *) - val v : t -> t' * Report.t list + val v : t -> t' end) : sig - 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) variable -> (pos, Report.t list -> E.t' * Report.t list) variable - - val variable' : (pos, E.t) variable -> (pos, E.t' * Report.t list) variable + val variable : (pos, E.t) variable -> (pos, E.t') variable (** Convert a variable from the [Expression.t] into [Expression.t'] *) end = struct - let v : E.t repr -> Report.t list -> E.t' * Report.t list = - fun v 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) variable -> (pos, E.t' * Report.t list) variable = - fun variable -> { variable with index = Option.map v' variable.index } + let variable : (pos, E.t) variable -> (pos, E.t') variable = + fun variable -> { variable with index = Option.map E.v variable.index } end -- cgit v1.2.3