tree.mli 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = {
  11. pos : 'a;
  12. name : string;
  13. index : 'a expression option;
  14. local : bool;
  15. }
  16. [@@deriving eq, show]
  17. (** A variable, used both in an expression (reference) or in a statement
  18. (assignation) *)
  19. and 'a expression =
  20. | Integer of 'a * string
  21. | Literal of 'a * 'a expression literal list
  22. | Ident of 'a variable
  23. | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
  24. | Op of 'a * T.uoperator * 'a expression
  25. | Function of 'a * T.function_ * 'a expression list
  26. [@@deriving eq, show]
  27. and 'a condition = 'a * 'a expression * 'a statement list
  28. (** A condition in if or elseif statement *)
  29. and 'a statement =
  30. | If of {
  31. loc : 'a;
  32. then_ : 'a condition;
  33. elifs : 'a condition list;
  34. else_ : 'a statement list;
  35. }
  36. | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
  37. | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
  38. | Expression of 'a expression
  39. | Comment of 'a
  40. | Call of 'a * T.keywords * 'a expression list
  41. | Location of 'a * string
  42. | For of {
  43. loc : 'a;
  44. variable : 'a variable;
  45. start : 'a expression;
  46. to_ : 'a expression;
  47. step : 'a expression option;
  48. statements : 'a statement list;
  49. }
  50. [@@deriving eq, show]
  51. end
  52. (** Extend the default Expression module with an eq operator *)
  53. module Expression : sig
  54. include S.Expression with type t' = S.pos Ast.expression
  55. val eq : (S.pos -> S.pos -> bool) -> t' -> t' -> bool
  56. val hash : (S.pos -> int) -> t' -> int
  57. val exists : f:(t' -> bool) -> t' -> bool
  58. end
  59. include
  60. S.Analyzer
  61. with module Expression := Expression
  62. and type Instruction.t' = S.pos Ast.statement
  63. and type Location.t = S.pos * S.pos Ast.statement list
  64. and type context = unit