From 582e95f9a880abcbbf072ae16ee0aa4fc2147110 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Tue, 11 Jun 2019 17:10:27 +0200 Subject: [PATCH] Enabled user-defined constant constructors in expressions. --- src/parser/pascaligo/AST.ml | 2 +- src/parser/pascaligo/AST.mli | 2 +- src/parser/pascaligo/Parser.mly | 5 ++++- src/parser/pascaligo/ParserLog.ml | 4 +++- src/simplify/pascaligo.ml | 13 ++++++++----- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/parser/pascaligo/AST.ml b/src/parser/pascaligo/AST.ml index 14557beda..8c4de5fd3 100644 --- a/src/parser/pascaligo/AST.ml +++ b/src/parser/pascaligo/AST.ml @@ -597,7 +597,7 @@ and nil = kwd_nil and constr_expr = SomeApp of (c_Some * arguments) reg | NoneExpr of none_expr -| ConstrApp of (constr * arguments) reg +| ConstrApp of (constr * arguments option) reg and record_expr = field_assign reg injection reg diff --git a/src/parser/pascaligo/AST.mli b/src/parser/pascaligo/AST.mli index ccb9b7712..eaa3d67b7 100644 --- a/src/parser/pascaligo/AST.mli +++ b/src/parser/pascaligo/AST.mli @@ -581,7 +581,7 @@ and nil = kwd_nil and constr_expr = SomeApp of (c_Some * arguments) reg | NoneExpr of none_expr -| ConstrApp of (constr * arguments) reg +| ConstrApp of (constr * arguments option) reg and record_expr = field_assign reg injection reg diff --git a/src/parser/pascaligo/Parser.mly b/src/parser/pascaligo/Parser.mly index 9c68a6e09..6ec70672f 100644 --- a/src/parser/pascaligo/Parser.mly +++ b/src/parser/pascaligo/Parser.mly @@ -956,7 +956,10 @@ core_expr: | projection { EProj $1 } | Constr arguments { let region = cover $1.region $2.region in - EConstr (ConstrApp {region; value = $1,$2}) + EConstr (ConstrApp {region; value = $1, Some $2}) + } +| Constr { + EConstr (ConstrApp {region=$1.region; value = $1,None}) } | C_Some arguments { let region = cover $1 $2.region in diff --git a/src/parser/pascaligo/ParserLog.ml b/src/parser/pascaligo/ParserLog.ml index 671e9d916..599543b4e 100644 --- a/src/parser/pascaligo/ParserLog.ml +++ b/src/parser/pascaligo/ParserLog.ml @@ -648,7 +648,9 @@ and print_fun_call {value; _} = and print_constr_app {value; _} = let constr, arguments = value in print_constr constr; - print_tuple_inj arguments + match arguments with + None -> () + | Some args -> print_tuple_inj args and print_some_app {value; _} = let c_Some, arguments = value in diff --git a/src/simplify/pascaligo.ml b/src/simplify/pascaligo.ml index 53e004688..922790453 100644 --- a/src/simplify/pascaligo.ml +++ b/src/simplify/pascaligo.ml @@ -416,11 +416,14 @@ let rec simpl_expression (t:Raw.expr) : expr result = | EProj p -> simpl_projection p | EConstr (ConstrApp c) -> ( let ((c, args) , loc) = r_split c in - let (args , args_loc) = r_split args in - let%bind arg = - simpl_tuple_expression ~loc:args_loc - @@ npseq_to_list args.inside in - return @@ e_constructor ~loc c.value arg + match args with + None -> simpl_tuple_expression [] + | Some args -> + let args, args_loc = r_split args in + let%bind arg = + simpl_tuple_expression ~loc:args_loc + @@ npseq_to_list args.inside in + return @@ e_constructor ~loc c.value arg ) | EConstr (SomeApp a) -> let ((_, args) , loc) = r_split a in