aboutsummaryrefslogtreecommitdiff
path: root/lib/syntax/nested_strings.ml
diff options
context:
space:
mode:
authorChimrod <>2023-11-08 16:30:02 +0100
committerChimrod <>2023-11-09 13:12:45 +0100
commitebf072326e2315ace952c80dbc442198c44faf7d (patch)
tree7f527035eb0627d634768246a0d14e1821d1bdc4 /lib/syntax/nested_strings.ml
parent1e182dca2972fbd29e50f611dbf12eb28d6cdd95 (diff)
Added a way to compose a test with another one
Diffstat (limited to 'lib/syntax/nested_strings.ml')
-rw-r--r--lib/syntax/nested_strings.ml98
1 files changed, 52 insertions, 46 deletions
diff --git a/lib/syntax/nested_strings.ml b/lib/syntax/nested_strings.ml
index c7b0b83..fcd0b91 100644
--- a/lib/syntax/nested_strings.ml
+++ b/lib/syntax/nested_strings.ml
@@ -4,62 +4,68 @@ let identifier = "escaped_string"
let description = "Check for unnecessary use of expression encoded in string"
let active = ref true
-module Expression : S.Expression with type t' = Report.t list = struct
- type t = Report.t list * Type_of.Expression.t
+module TypeBuilder = Compose.Expression (Get_type)
+
+module Expression = TypeBuilder.Make (struct
+ type t = Report.t list
type t' = Report.t list
- let get_type t = Type_of.Expression.v t |> Type_of.get_type
- let v : t -> t' = Stdlib.fst
+ let v : Get_type.t * t -> t' = snd
(** Identify the expressions reprented as string. That’s here that the report
are added.
All the rest of the module only push thoses warning to the top level. *)
- let literal : S.pos -> t T.literal list -> t =
- fun pos content ->
- let type_of =
- List.map content ~f:(function
- | T.Text _ as text -> text
- | T.Expression expr -> T.Expression (List.map ~f:snd expr))
- |> Type_of.Expression.literal pos
- in
-
+ let literal : S.pos -> (Get_type.t * t) T.literal list -> Get_type.t -> t =
+ fun pos content _type_of ->
match content with
- | [ T.Expression [ (_, t') ]; T.Text "" ] -> (
- match get_type t' with
- | Type_of.Helper.Integer -> ([], type_of)
+ | [ T.Expression [ (t', _) ]; T.Text "" ] -> (
+ match Get_type.get_type t' with
+ | Get_type.Integer -> []
| _ ->
let msg = Report.debug pos "This expression can be simplified" in
- ([ msg ], type_of))
- | _ -> ([], type_of)
-
- let ident : (S.pos, t) S.variable -> t =
- fun { pos; name : string; index : t option } ->
- match index with
- | None ->
- let type_ = Type_of.Expression.ident { pos; name; index = None } in
- ([], type_)
- | Some (v, t') ->
- let type_ = Type_of.Expression.ident { pos; name; index = Some t' } in
- (v, type_)
-
- let integer : S.pos -> string -> t =
- fun pos t -> ([], Type_of.Expression.integer pos t)
-
- let function_ : S.pos -> T.function_ -> t list -> t =
- fun pos f expressions ->
- let r, t = List.split expressions in
-
- let type_of = Type_of.Expression.function_ pos f t in
- (List.concat r, type_of)
-
- let uoperator : S.pos -> T.uoperator -> t -> t =
- fun pos op (r, expr1) -> (r, Type_of.Expression.uoperator pos op expr1)
-
- let boperator : S.pos -> T.boperator -> t -> t -> t =
- fun pos op (r1, expr1) (r2, expr2) ->
- (r1 @ r2, Type_of.Expression.boperator pos op expr1 expr2)
-end
+ [ msg ])
+ | _ -> []
+
+ let ident : (S.pos, Get_type.t * t) S.variable -> Get_type.t -> t =
+ fun variable _type_of ->
+ match variable.index with None -> [] | Some (_, t) -> t
+
+ let integer : S.pos -> string -> Get_type.t -> t =
+ fun pos t _type_of ->
+ ignore pos;
+ ignore t;
+ []
+
+ let function_ :
+ S.pos -> T.function_ -> (Get_type.t * t) list -> Get_type.t -> t =
+ fun pos f expressions _type_of ->
+ ignore pos;
+ ignore f;
+ let exprs =
+ List.fold_left ~init:[] expressions ~f:(fun acc el ->
+ List.rev_append (snd el) acc)
+ in
+ exprs
+
+ let uoperator : S.pos -> T.uoperator -> Get_type.t * t -> Get_type.t -> t =
+ fun pos op r _type_of ->
+ ignore op;
+ ignore pos;
+ snd r
+
+ let boperator :
+ S.pos ->
+ T.boperator ->
+ Get_type.t * t ->
+ Get_type.t * t ->
+ Get_type.t ->
+ t =
+ fun pos op (_, r1) (_, r2) _type_of ->
+ ignore pos;
+ ignore op;
+ r1 @ r2
+end)
module Instruction :
S.Instruction with type t' = Report.t list and type expression = Expression.t' =