12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- (**
- Implementation for S.Analyzer for building a complete Ast.
- Used in the unit test in order to check if the grammar is interpreted as
- expected, not really usefull over a big qsp.
- *)
- (** This module is the result of the evaluation. *)
- module Ast : sig
- type 'a literal = 'a T.literal = Text of string | Expression of 'a
- [@@deriving eq, show]
- type 'a variable = {
- pos : 'a;
- name : string;
- index : 'a expression option;
- local : bool;
- }
- [@@deriving eq, show]
- (** A variable, used both in an expression (reference) or in a statement
- (assignation) *)
- and 'a expression =
- | Integer of 'a * string
- | Literal of 'a * 'a expression literal list
- | Ident of 'a variable
- | BinaryOp of 'a * T.boperator * 'a expression * 'a expression
- | Op of 'a * T.uoperator * 'a expression
- | Function of 'a * T.function_ * 'a expression list
- [@@deriving eq, show]
- and 'a condition = 'a * 'a expression * 'a statement list
- (** A condition in if or elseif statement *)
- and 'a statement =
- | If of {
- loc : 'a;
- then_ : 'a condition;
- elifs : 'a condition list;
- else_ : 'a statement list;
- }
- | Act of { loc : 'a; label : 'a expression; statements : 'a statement list }
- | Declaration of ('a * 'a variable * T.assignation_operator * 'a expression)
- | Expression of 'a expression
- | Comment of 'a
- | Call of 'a * T.keywords * 'a expression list
- | Location of 'a * string
- | For of {
- loc : 'a;
- variable : 'a variable;
- start : 'a expression;
- to_ : 'a expression;
- step : 'a expression option;
- statements : 'a statement list;
- }
- [@@deriving eq, show]
- end
- (** Extend the default Expression module with an eq operator *)
- module Expression : sig
- include S.Expression with type t' = S.pos Ast.expression
- val eq : (S.pos -> S.pos -> bool) -> t' -> t' -> bool
- val hash : (S.pos -> int) -> t' -> int
- val exists : f:(t' -> bool) -> t' -> bool
- end
- include
- S.Analyzer
- with module Expression := Expression
- and type Instruction.t' = S.pos Ast.statement
- and type Location.t = S.pos * S.pos Ast.statement list
- and type context = unit
|