tree.mli 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. | For of {
  38. loc : 'a;
  39. variable : 'a variable;
  40. start : 'a expression;
  41. to_ : 'a expression;
  42. step : 'a expression option;
  43. statements : 'a statement list;
  44. }
  45. [@@deriving eq, show]
  46. end
  47. (** Extend the default Expression module with an eq operator *)
  48. module Expression : sig
  49. include S.Expression with type t' = S.pos Ast.expression
  50. val eq : (S.pos -> S.pos -> bool) -> t' -> t' -> bool
  51. val hash : (S.pos -> int) -> t' -> int
  52. val exists : f:(t' -> bool) -> t' -> bool
  53. end
  54. include
  55. S.Analyzer
  56. with module Expression := Expression
  57. and type Instruction.t' = S.pos Ast.statement
  58. and type Location.t = S.pos * S.pos Ast.statement list
  59. and type context = unit