aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/qparser/qsp_expression.mly4
-rw-r--r--lib/syntax/check.ml23
-rw-r--r--lib/syntax/get_type.ml10
-rw-r--r--lib/syntax/nested_strings.ml2
-rw-r--r--lib/syntax/t.ml8
-rw-r--r--lib/syntax/tree.ml2
-rw-r--r--lib/syntax/tree.mli2
-rw-r--r--lib/syntax/type_of.ml15
8 files changed, 15 insertions, 51 deletions
diff --git a/lib/qparser/qsp_expression.mly b/lib/qparser/qsp_expression.mly
index 9375701..1e0988f 100644
--- a/lib/qparser/qsp_expression.mly
+++ b/lib/qparser/qsp_expression.mly
@@ -46,8 +46,8 @@
}
literal:
| v = LITERAL { Qsp_syntax.T.Text v }
- | e = delimited(ENTER_EMBED, expression*, LEAVE_EMBED)
- { Qsp_syntax.T.Expression e }
+ | e = delimited(ENTER_EMBED, expression, LEAVE_EMBED)
+ { Qsp_syntax.T.Expression e }
unary_operator:
| OBJ
diff --git a/lib/syntax/check.ml b/lib/syntax/check.ml
index c5dfe74..6737e80 100644
--- a/lib/syntax/check.ml
+++ b/lib/syntax/check.ml
@@ -124,13 +124,12 @@ module Make (A : App) = struct
Array.mapi A.t ~f:(fun i (E { module_ = (module S); expr_witness; _ }) ->
(* Map every values to the Checker *)
let values' =
- List.map values ~f:(function
- | T.Text t -> T.Text t
- | T.Expression e ->
- let exprs =
- List.rev (Helper.expr_i e expr_witness i).values
- in
- T.Expression exprs)
+ List.map values
+ ~f:
+ (T.map_litteral ~f:(fun expr ->
+ match get expr_witness (Array.get expr i) with
+ | None -> failwith "Does not match"
+ | Some value -> value))
in
let value = S.Expression.literal pos values' in
R { value; witness = expr_witness })
@@ -320,15 +319,6 @@ module Make (A : App) = struct
R { value; witness = instr_witness })
- (** Helper function used to prepare the clauses *)
- let map_clause : (expression, t) S.clause -> S.pos * Expression.t' * t list
- =
- fun clause ->
- let clause_pos, expression, t = clause in
- let expression = expression in
- let clause = (clause_pos, expression, t) in
- clause
-
let rebuild_clause :
type a b.
int ->
@@ -354,7 +344,6 @@ module Make (A : App) = struct
t =
fun pos clause ~elifs ~else_ ->
(* First, apply the report for all the instructions *)
- let clause = map_clause clause and elifs = List.map elifs ~f:map_clause in
let else_ =
match else_ with
| None -> None
diff --git a/lib/syntax/get_type.ml b/lib/syntax/get_type.ml
index 4aecb01..2bd12bb 100644
--- a/lib/syntax/get_type.ml
+++ b/lib/syntax/get_type.ml
@@ -35,15 +35,7 @@ let literal : S.pos -> t T.literal list -> t =
List.fold_left values ~init ~f:(fun state -> function
| T.Text t -> (
match int_of_string_opt t with Some _ -> state | None -> Raw String)
- | T.Expression t ->
- (* Report the warning bottom top *)
- let result =
- List.fold_left t ~init:None ~f:(fun _ result -> Some result)
- in
- let default = Raw String in
- let result = Option.value result ~default in
-
- result)
+ | T.Expression t -> t)
let uoperator : S.pos -> T.uoperator -> t -> t =
fun pos operator t ->
diff --git a/lib/syntax/nested_strings.ml b/lib/syntax/nested_strings.ml
index 7e49ace..4dd5c81 100644
--- a/lib/syntax/nested_strings.ml
+++ b/lib/syntax/nested_strings.ml
@@ -21,7 +21,7 @@ module Expression = TypeBuilder.Make (struct
=
fun pos content _type_of ->
match content with
- | [ T.Expression [ (t', _) ]; T.Text "" ] -> (
+ | [ T.Expression (t', _); T.Text "" ] -> (
match Get_type.get_type (Lazy.force t') with
| Get_type.Integer -> []
| _ ->
diff --git a/lib/syntax/t.ml b/lib/syntax/t.ml
index 38ad5b0..c50d2e2 100644
--- a/lib/syntax/t.ml
+++ b/lib/syntax/t.ml
@@ -2,14 +2,10 @@
This module contains the basic operators used in the QSP syntax.
*)
-open StdLabels
-
-type 'a literal = Text of string | Expression of 'a list
+type 'a literal = Text of string | Expression of 'a
let map_litteral : f:('a -> 'b) -> 'a literal -> 'b literal =
- fun ~f -> function
- | Text t -> Text t
- | Expression e -> Expression (List.map ~f e)
+ fun ~f -> function Text t -> Text t | Expression e -> Expression (f e)
type boperator =
| Eq
diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml
index 6f99bbd..21238a6 100644
--- a/lib/syntax/tree.ml
+++ b/lib/syntax/tree.ml
@@ -5,7 +5,7 @@ let description = "Build the AST"
let active = ref true
module Ast = struct
- type 'a literal = 'a T.literal = Text of string | Expression of 'a list
+ type 'a literal = 'a T.literal = Text of string | Expression of 'a
[@@deriving eq, show]
type 'a variable = { pos : 'a; name : string; index : 'a expression option }
diff --git a/lib/syntax/tree.mli b/lib/syntax/tree.mli
index 0032f03..c5506e7 100644
--- a/lib/syntax/tree.mli
+++ b/lib/syntax/tree.mli
@@ -7,7 +7,7 @@
(** This module is the result of the evaluation. *)
module Ast : sig
- type 'a literal = 'a T.literal = Text of string | Expression of 'a list
+ type 'a literal = 'a T.literal = Text of string | Expression of 'a
[@@deriving eq, show]
type 'a variable = { pos : 'a; name : string; index : 'a expression option }
diff --git a/lib/syntax/type_of.ml b/lib/syntax/type_of.ml
index c532a96..d132162 100644
--- a/lib/syntax/type_of.ml
+++ b/lib/syntax/type_of.ml
@@ -191,20 +191,7 @@ module TypedExpression = struct
| T.Text t ->
let empty = String.equal t String.empty in
({ pos; empty }, report)
- | T.Expression (t : (Get_type.t Lazy.t * t) list) ->
- (* Report the warning bottom top *)
- let result, r =
- List.fold_left t ~init:(None, [])
- ~f:(fun (_, report) (type_of, t) ->
- ignore type_of;
- let r = snd t in
- let report = List.rev_append r report in
- (Some { pos; empty = false }, report))
- in
- let default = { pos; empty = true } in
- let result = Option.value result ~default in
-
- (result, r))
+ | T.Expression t -> snd t)
in
result