diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/qparser/parser.mly | 2 | ||||
-rw-r--r-- | lib/syntax/S.ml | 10 | ||||
-rw-r--r-- | lib/syntax/tree.ml | 8 | ||||
-rw-r--r-- | lib/syntax/type_of.ml | 20 |
4 files changed, 28 insertions, 12 deletions
diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index 8547e17..556a9ec 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -11,7 +11,7 @@ ; body : Analyzer.Instruction.t Qsp_syntax.S.repr list ; pos : Qsp_syntax.S.pos ; else_ : ( - ( Analyzer.Instruction.clause list + ( (Analyzer.Instruction.expression, Analyzer.Instruction.t) Qsp_syntax.S.clause list * Analyzer.Instruction.t Qsp_syntax.S.repr list ) option ) } diff --git a/lib/syntax/S.ml b/lib/syntax/S.ml index 3b24aff..e6c472d 100644 --- a/lib/syntax/S.ml +++ b/lib/syntax/S.ml @@ -24,6 +24,8 @@ type ('a, 'b) variable = { pos : 'a; name : string; index : 'b option } If missing, the index should be considered as [0].*) +type ('a, 'b) clause = pos * 'a * 'b repr list + (** Represent the evaluation over an expression *) module type Expression = sig type t @@ -75,9 +77,13 @@ module type Instruction = sig val expression : expression -> t repr (** Raw expression *) - type clause = pos * expression * t repr list + val if_ : + pos -> + (expression, t) clause -> + elifs:(expression, t) clause list -> + else_:t repr list -> + t repr - val if_ : pos -> clause -> elifs:clause list -> else_:t repr list -> t repr val act : pos -> label:expression -> t repr list -> t repr val assign : diff --git a/lib/syntax/tree.ml b/lib/syntax/tree.ml index 02c6b36..db8abd9 100644 --- a/lib/syntax/tree.ml +++ b/lib/syntax/tree.ml @@ -89,10 +89,12 @@ module Instruction : let expression : expression -> t S.repr = fun expr report -> (Ast.Expression (fst (expr [])), report) - type clause = S.pos * expression * t S.repr list - let if_ : - S.pos -> clause -> elifs:clause list -> else_:t S.repr list -> t S.repr = + S.pos -> + (expression, t) S.clause -> + elifs:(expression, t) S.clause list -> + else_:t S.repr list -> + t S.repr = fun pos predicate ~elifs ~else_ report -> let clause (pos, expr, repr) = let repr = List.map ~f:(fun instr -> fst @@ instr []) repr in diff --git a/lib/syntax/type_of.ml b/lib/syntax/type_of.ml index 83258cc..a04d37b 100644 --- a/lib/syntax/type_of.ml +++ b/lib/syntax/type_of.ml @@ -126,8 +126,13 @@ module Expression = struct let integer : S.pos -> string -> t S.repr = fun pos value report -> - let empty = - match int_of_string_opt value with Some 0 -> true | _ -> false + let int_value = int_of_string_opt value in + + let empty, report = + match int_value with + | Some 0 -> (true, report) + | Some _ -> (false, report) + | None -> (false, Report.error pos "Invalid integer value" :: report) in ({ result = Integer; pos; empty }, report) @@ -308,13 +313,16 @@ module Instruction = struct let expression : expression -> t S.repr = fun expression report -> ((), snd (expression report)) - type clause = S.pos * expression * t S.repr list - let if_ : - S.pos -> clause -> elifs:clause list -> else_:t S.repr list -> t S.repr = + S.pos -> + (expression, t) S.clause -> + elifs:(expression, t) S.clause list -> + else_:t S.repr list -> + t S.repr = fun _pos clause ~elifs ~else_ report -> (* Helper function *) - let fold_clause : t * Report.t list -> clause -> t * Report.t list = + let fold_clause : + t * Report.t list -> (expression, t) S.clause -> t * Report.t list = fun ((), report) (_pos, expr, instructions) -> let result, report = expr report in let report = |