tree.mli 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. (**
  2. Implementation for S.Analyzer for building a complete Ast.
  3. Used in the unit test in order to check if the grammar is interpreted as
  4. expected, not really usefull over a big qsp.
  5. *)
  6. (** This module is the result of the evaluation. *)
  7. module Ast : sig
  8. type 'a literal = 'a T.literal = Text of string | Expression of 'a
  9. [@@deriving eq, show]
  10. type 'a variable = { pos : 'a; name : string; index : 'a expression option }
  11. [@@deriving eq, show]
  12. (** A variable, used both in an expression (reference) or in a statement
  13. (assignation) *)
  14. and 'a expression =
  15. | Integer of 'a * string
  16. | Literal of 'a * 'a expression literal list
  17. | Ident of 'a variable
  18. | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
  19. | Op of 'a * T.uoperator * 'a expression
  20. | Function of 'a * T.function_ * 'a expression list
  21. [@@deriving eq, show]
  22. and 'a condition = 'a * 'a expression * 'a statement list
  23. (** A condition in if or elseif statement *)
  24. and 'a statement =
  25. | If of {
  26. loc : 'a;
  27. then_ : 'a condition;
  28. elifs : 'a condition list;
  29. else_ : 'a statement list;
  30. }
  31. | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
  32. | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
  33. | Expression of 'a expression
  34. | Comment of 'a
  35. | Call of 'a * T.keywords * 'a expression list
  36. | Location of 'a * string
  37. [@@deriving eq, show]
  38. end
  39. (** Extend the default Expression module with an eq operator *)
  40. module Expression : sig
  41. include S.Expression with type t' = S.pos Ast.expression
  42. val eq : (S.pos -> S.pos -> bool) -> t' -> t' -> bool
  43. val hash : (S.pos -> int) -> t' -> int
  44. val exists : f:(t' -> bool) -> t' -> bool
  45. end
  46. include
  47. S.Analyzer
  48. with module Expression := Expression
  49. and type Instruction.t' = S.pos Ast.statement
  50. and type Location.t = S.pos * S.pos Ast.statement list
  51. and type context = unit