aboutsummaryrefslogtreecommitdiff
path: root/lib/syntax
diff options
context:
space:
mode:
authorChimrod <>2023-10-28 22:17:24 +0200
committerChimrod <>2023-11-02 11:06:12 +0100
commit77ae152ece4efbf8dde983c03bd995c982522bfd (patch)
treeb6427477b66042f766e58148441166b83984ddbb /lib/syntax
parentdd060261e35fcb8a57f03b01dbe84ab772a2a199 (diff)
Updated the interface
Diffstat (limited to 'lib/syntax')
-rw-r--r--lib/syntax/S.ml2
-rw-r--r--lib/syntax/check.ml18
-rw-r--r--lib/syntax/default.ml2
-rw-r--r--lib/syntax/t.ml2
-rw-r--r--lib/syntax/tree.ml9
-rw-r--r--lib/syntax/tree.mli5
-rw-r--r--lib/syntax/type_of.ml35
7 files changed, 56 insertions, 17 deletions
diff --git a/lib/syntax/S.ml b/lib/syntax/S.ml
index 108dac9..f7c3ebe 100644
--- a/lib/syntax/S.ml
+++ b/lib/syntax/S.ml
@@ -40,7 +40,7 @@ module type Expression = sig
*)
val integer : pos -> string -> t
- val literal : pos -> string -> t
+ val literal : pos -> t T.literal list -> t
val function_ : pos -> T.function_ -> t list -> t
(** Call a function. The functions list is hardcoded in lib/lexer.mll *)
diff --git a/lib/syntax/check.ml b/lib/syntax/check.ml
index 7db3286..2528914 100644
--- a/lib/syntax/check.ml
+++ b/lib/syntax/check.ml
@@ -112,10 +112,20 @@ module Make (A : App) = struct
type t = result array
type t' = result array
- let literal : S.pos -> string -> t =
- fun pos value ->
- Array.map A.t ~f:(fun (E { module_ = (module S); expr_witness; _ }) ->
- let value = S.Expression.literal pos value in
+ let literal : S.pos -> t T.literal list -> t =
+ fun pos values ->
+ 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)
+ in
+ let value = S.Expression.literal pos values' in
R { value; witness = expr_witness })
let integer : S.pos -> string -> t =
diff --git a/lib/syntax/default.ml b/lib/syntax/default.ml
index 45e7c14..9e9a8ef 100644
--- a/lib/syntax/default.ml
+++ b/lib/syntax/default.ml
@@ -24,7 +24,7 @@ module Expression (T' : T) = struct
*)
let integer : S.pos -> string -> T'.t = fun _ _ -> T'.default
- let literal : S.pos -> string -> T'.t = fun _ _ -> T'.default
+ let literal : S.pos -> T'.t T.literal list -> T'.t = fun _ _ -> T'.default
(** Call a function. The functions list is hardcoded in lib/lexer.mll *)
let function_ : S.pos -> T.function_ -> T'.t list -> T'.t =
diff --git a/lib/syntax/t.ml b/lib/syntax/t.ml
index bf31253..ade5e11 100644
--- a/lib/syntax/t.ml
+++ b/lib/syntax/t.ml
@@ -2,6 +2,8 @@
This module contains the basic operators used in the QSP syntax.
*)
+type 'a literal = Text of string | Expression of 'a list
+
type boperator =
| Eq
| Neq
diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml
index d4af905..34baae0 100644
--- a/lib/syntax/tree.ml
+++ b/lib/syntax/tree.ml
@@ -1,12 +1,15 @@
open StdLabels
module Ast = struct
+ type 'a literal = 'a T.literal = Text of string | Expression of 'a list
+ [@@deriving eq, show]
+
type 'a variable = { pos : 'a; name : string; index : 'a expression option }
[@@deriving eq, show]
and 'a expression =
| Integer of 'a * string
- | Literal of 'a * string
+ | Literal of 'a * 'a expression literal list
| Ident of 'a variable
| BinaryOp of 'a * T.boperator * 'a expression * 'a expression
| Op of 'a * T.uoperator * 'a expression
@@ -38,7 +41,9 @@ module Expression : S.Expression with type t' = S.pos Ast.expression = struct
let v : t -> t' = fun t -> t
let integer : S.pos -> string -> t = fun pos i -> Ast.Integer (pos, i)
- let literal : S.pos -> string -> t = fun pos l -> Ast.Literal (pos, l)
+
+ let literal : S.pos -> t T.literal list -> t =
+ fun pos l -> Ast.Literal (pos, l)
let function_ : S.pos -> T.function_ -> t list -> t =
fun pos name args -> Ast.Function (pos, name, args)
diff --git a/lib/syntax/tree.mli b/lib/syntax/tree.mli
index 84e5d1b..0032f03 100644
--- a/lib/syntax/tree.mli
+++ b/lib/syntax/tree.mli
@@ -7,6 +7,9 @@
(** This module is the result of the evaluation. *)
module Ast : sig
+ type 'a literal = 'a T.literal = Text of string | Expression of 'a list
+ [@@deriving eq, show]
+
type 'a variable = { pos : 'a; name : string; index : 'a expression option }
[@@deriving eq, show]
(** A variable, used both in an expression (reference) or in a statement
@@ -14,7 +17,7 @@ module Ast : sig
and 'a expression =
| Integer of 'a * string
- | Literal of 'a * string
+ | Literal of 'a * 'a expression literal list
| Ident of 'a variable
| BinaryOp of 'a * T.boperator * 'a expression * 'a expression
| Op of 'a * T.uoperator * 'a expression
diff --git a/lib/syntax/type_of.ml b/lib/syntax/type_of.ml
index d0bf31d..ce04872 100644
--- a/lib/syntax/type_of.ml
+++ b/lib/syntax/type_of.ml
@@ -184,15 +184,34 @@ module Expression = struct
({ result = Raw Integer; pos; empty }, report)
- let literal : S.pos -> string -> t =
- fun pos value ->
- let empty = String.equal String.empty value in
- let type_of =
- match int_of_string_opt value with
- | Some _ -> Helper.NumericString
- | None -> Helper.String
+ let literal : S.pos -> t T.literal list -> t =
+ fun pos values ->
+ let init = ({ result = Raw Helper.NumericString; pos; empty = true }, []) in
+ let result =
+ List.fold_left values ~init ~f:(fun (state, report) -> function
+ | T.Text t ->
+ let empty = String.equal t String.empty in
+ let type_of =
+ match int_of_string_opt t with
+ | Some _ -> state.result
+ | None -> Raw Helper.String
+ in
+ ({ result = type_of; pos; empty }, report)
+ | T.Expression t ->
+ (* Report the warning bottom top *)
+ let result, r =
+ List.fold_left t ~init:(None, [])
+ ~f:(fun (_, report) (result, r) ->
+ let report = List.rev_append r report in
+ (Some { result = result.result; pos; empty = false }, report))
+ in
+ let default = { result = Raw Helper.String; pos; empty = true } in
+ let result = Option.value result ~default in
+
+ (result, r))
in
- ({ result = Raw type_of; pos; empty }, [])
+
+ result
let function_ : S.pos -> T.function_ -> t list -> t =
fun pos function_ params ->