diff options
author | Chimrod <> | 2023-10-25 18:41:27 +0200 |
---|---|---|
committer | Chimrod <> | 2023-10-25 20:33:12 +0200 |
commit | 319c1e4474f4fefde688720b78e8abf315513a32 (patch) | |
tree | 12908fcf3f2efdac2cd4cf8613807bc598d13bcb /lib/syntax/tree.ml | |
parent | 2a2198e91063684a1b19974acc19c25b55266724 (diff) |
Now I have the API I want. Everything is abstract in the type S.Analyzer
Diffstat (limited to 'lib/syntax/tree.ml')
-rw-r--r-- | lib/syntax/tree.ml | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml index cf02bf6..d4af905 100644 --- a/lib/syntax/tree.ml +++ b/lib/syntax/tree.ml @@ -36,7 +36,7 @@ module Expression : S.Expression with type t' = S.pos Ast.expression = struct type t = S.pos Ast.expression type t' = t - let v : t -> t' * Report.t list = fun t -> (t, []) + 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) @@ -59,78 +59,57 @@ end module Instruction : S.Instruction - with type expression = Expression.t' * Report.t list + with type expression = Expression.t' and type t' = S.pos Ast.statement = struct type t = S.pos Ast.statement type t' = t - let v : t -> t' * Report.t list = fun t -> (t, []) + let v : t -> t' = fun t -> t - type expression = Expression.t' * Report.t list + type expression = Expression.t' - let call : S.pos -> T.keywords -> expression list -> t S.repr = - fun pos name args _ -> - let args = List.map ~f:fst args in - Ast.Call (pos, name, args) + let call : S.pos -> T.keywords -> expression list -> t = + fun pos name args -> Ast.Call (pos, name, args) - let location : S.pos -> string -> t S.repr = - fun loc label _ -> Ast.Location (loc, label) + let location : S.pos -> string -> t = + fun loc label -> Ast.Location (loc, label) - let comment : S.pos -> t S.repr = fun pos _ -> Ast.Comment pos - - let expression : expression -> t S.repr = - fun expr _ -> Ast.Expression (fst expr) + let comment : S.pos -> t = fun pos -> Ast.Comment pos + let expression : expression -> t = fun expr -> Ast.Expression expr let if_ : S.pos -> (expression, t) S.clause -> elifs:(expression, t) S.clause list -> - else_:(S.pos * t S.repr list) option -> - t S.repr = - fun pos predicate ~elifs ~else_ _ -> - let clause (pos, expr, repr) = - let repr = List.map ~f:(fun instr -> instr []) repr in - (pos, fst @@ expr, repr) - in + else_:(S.pos * t list) option -> + t = + fun pos predicate ~elifs ~else_ -> + let clause (pos, expr, repr) = (pos, expr, repr) in let elifs = List.map ~f:clause elifs and else_ = - match else_ with - | None -> [] - | Some (_, instructions) -> - List.map ~f:(fun instr -> instr []) instructions + match else_ with None -> [] | Some (_, instructions) -> instructions in Ast.If { loc = pos; then_ = clause predicate; elifs; else_ } - let act : S.pos -> label:expression -> t S.repr list -> t S.repr = - fun pos ~label statements _ -> - let label = fst label - and statements = List.map ~f:(fun instr -> instr []) statements in - Ast.Act { loc = pos; label; statements } + let act : S.pos -> label:expression -> t list -> t = + fun pos ~label statements -> Ast.Act { loc = pos; label; statements } let assign : S.pos -> (S.pos, expression) S.variable -> T.assignation_operator -> expression -> - t S.repr = - fun pos_loc { pos; name; index } op expr _ -> + t = + fun pos_loc { pos; name; index } op expr -> (*let index = Option.map (fun i -> fst @@ Expression.observe (i [])) index*) - let index = Option.map fst index in - let expr = fst expr in Ast.Declaration (pos_loc, { pos; name; index }, op, expr) end module Location = struct - type instruction = (Instruction.t' * Report.t list) S.repr + type instruction = Instruction.t' type t = S.pos * S.pos Ast.statement list - let location : S.pos -> instruction list -> (t * Report.t list) S.repr = - fun pos block report -> - let report, block = - List.fold_left_map ~init:report block ~f:(fun report b -> - let v, report = b report in - (report, v)) - in - ((pos, block), report) + let location : S.pos -> instruction list -> t * Report.t list = + fun pos block -> ((pos, block), []) end |