From 5f129d924a4e8c84d88a13d5a2362d14284e4d8f Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 14 Mar 2019 14:04:20 +0100 Subject: [PATCH] Removed storage and operations declarations: entry-points now take the former and return the latter. --- AST.ml | 53 ++++++++-------------------------- AST.mli | 24 +++------------- LexToken.mli | 2 -- LexToken.mll | 10 ------- ParToken.mly | 2 -- Parser.mly | 80 ++++++++++++++++------------------------------------ Tests/a.li | 9 +++--- 7 files changed, 44 insertions(+), 136 deletions(-) diff --git a/AST.ml b/AST.ml index 0854f624d..435c9770f 100644 --- a/AST.ml +++ b/AST.ml @@ -57,11 +57,9 @@ type kwd_mod = Region.t type kwd_not = Region.t type kwd_null = Region.t type kwd_of = Region.t -type kwd_operations = Region.t type kwd_procedure = Region.t type kwd_record = Region.t type kwd_step = Region.t -type kwd_storage = Region.t type kwd_then = Region.t type kwd_to = Region.t type kwd_type = Region.t @@ -157,8 +155,6 @@ and ast = t and declaration = TypeDecl of type_decl reg | ConstDecl of const_decl reg -| StorageDecl of storage_decl reg -| OpDecl of operations_decl reg | LambdaDecl of lambda_decl and const_decl = { @@ -171,22 +167,6 @@ and const_decl = { terminator : semi option } -and storage_decl = { - kwd_storage : kwd_storage; - name : variable; - colon : colon; - store_type : type_expr; - terminator : semi option -} - -and operations_decl = { - kwd_operations : kwd_operations; - name : variable; - colon : colon; - op_type : type_expr; - terminator : semi option -} - (* Type declarations *) and type_decl = { @@ -264,9 +244,13 @@ and entry_decl = { kwd_entrypoint : kwd_entrypoint; name : variable; param : parameters; + colon : colon; + ret_type : type_expr; kwd_is : kwd_is; local_decls : local_decl list; block : block reg; + kwd_with : kwd_with; + return : expr; terminator : semi option } @@ -742,8 +726,6 @@ let rec print_tokens ast = and print_decl = function TypeDecl decl -> print_type_decl decl | ConstDecl decl -> print_const_decl decl -| StorageDecl decl -> print_storage_decl decl -| OpDecl decl -> print_operations_decl decl | LambdaDecl decl -> print_lambda_decl decl and print_const_decl {value; _} = @@ -757,24 +739,6 @@ and print_const_decl {value; _} = print_expr init; print_terminator terminator -and print_storage_decl {value; _} = - let {kwd_storage; name; colon; - store_type; terminator} = value in - print_token kwd_storage "storage"; - print_var name; - print_token colon ":"; - print_type_expr store_type; - print_terminator terminator - -and print_operations_decl {value; _} = - let {kwd_operations; name; colon; - op_type; terminator} = value in - print_token kwd_operations "operations"; - print_var name; - print_token colon ":"; - print_type_expr op_type; - print_terminator terminator - and print_type_decl {value; _} = let {kwd_type; name; kwd_is; type_expr; terminator} = value in @@ -869,14 +833,19 @@ and print_proc_decl {value; _} = print_terminator terminator and print_entry_decl {value; _} = - let {kwd_entrypoint; name; param; kwd_is; - local_decls; block; terminator} = value in + let {kwd_entrypoint; name; param; colon; + ret_type; kwd_is; local_decls; + block; kwd_with; return; terminator} = value in print_token kwd_entrypoint "entrypoint"; print_var name; print_parameters param; + print_token colon ":"; + print_type_expr ret_type; print_token kwd_is "is"; print_local_decls local_decls; print_block block; + print_token kwd_with "with"; + print_expr return; print_terminator terminator and print_parameters {value; _} = diff --git a/AST.mli b/AST.mli index ce6b045c1..92ab2a8ad 100644 --- a/AST.mli +++ b/AST.mli @@ -41,11 +41,9 @@ type kwd_mod = Region.t type kwd_not = Region.t type kwd_null = Region.t type kwd_of = Region.t -type kwd_operations = Region.t type kwd_procedure = Region.t type kwd_record = Region.t type kwd_step = Region.t -type kwd_storage = Region.t type kwd_then = Region.t type kwd_to = Region.t type kwd_type = Region.t @@ -141,8 +139,6 @@ and ast = t and declaration = TypeDecl of type_decl reg | ConstDecl of const_decl reg -| StorageDecl of storage_decl reg -| OpDecl of operations_decl reg | LambdaDecl of lambda_decl and const_decl = { @@ -155,22 +151,6 @@ and const_decl = { terminator : semi option } -and storage_decl = { - kwd_storage : kwd_storage; - name : variable; - colon : colon; - store_type : type_expr; - terminator : semi option -} - -and operations_decl = { - kwd_operations : kwd_operations; - name : variable; - colon : colon; - op_type : type_expr; - terminator : semi option -} - (* Type declarations *) and type_decl = { @@ -248,9 +228,13 @@ and entry_decl = { kwd_entrypoint : kwd_entrypoint; name : variable; param : parameters; + colon : colon; + ret_type : type_expr; kwd_is : kwd_is; local_decls : local_decl list; block : block reg; + kwd_with : kwd_with; + return : expr; terminator : semi option } diff --git a/LexToken.mli b/LexToken.mli index efbcad545..73965263b 100644 --- a/LexToken.mli +++ b/LexToken.mli @@ -78,10 +78,8 @@ type t = | Entrypoint of Region.t (* "entrypoint" *) | For of Region.t (* "for" *) | Function of Region.t (* "function" *) -| Storage of Region.t (* "storage" *) | Type of Region.t (* "type" *) | Of of Region.t (* "of" *) -| Operations of Region.t (* "operations" *) | Var of Region.t (* "var" *) | End of Region.t (* "end" *) | Then of Region.t (* "then" *) diff --git a/LexToken.mll b/LexToken.mll index 5a3bbd5ff..5994d352b 100644 --- a/LexToken.mll +++ b/LexToken.mll @@ -77,10 +77,8 @@ type t = | Entrypoint of Region.t | For of Region.t | Function of Region.t -| Storage of Region.t | Type of Region.t | Of of Region.t -| Operations of Region.t | Var of Region.t | End of Region.t | Then of Region.t @@ -197,10 +195,8 @@ let proj_token = function | Entrypoint region -> region, "Entrypoint" | For region -> region, "For" | Function region -> region, "Function" -| Storage region -> region, "Storage" | Type region -> region, "Type" | Of region -> region, "Of" -| Operations region -> region, "Operations" | Var region -> region, "Var" | End region -> region, "End" | Then region -> region, "Then" @@ -282,10 +278,8 @@ let to_lexeme = function | Entrypoint _ -> "entrypoint" | For _ -> "for" | Function _ -> "function" -| Storage _ -> "storage" | Type _ -> "type" | Of _ -> "of" -| Operations _ -> "operations" | Var _ -> "var" | End _ -> "end" | Then _ -> "then" @@ -335,10 +329,8 @@ let keywords = [ (fun reg -> Entrypoint reg); (fun reg -> For reg); (fun reg -> Function reg); - (fun reg -> Storage reg); (fun reg -> Type reg); (fun reg -> Of reg); - (fun reg -> Operations reg); (fun reg -> Var reg); (fun reg -> End reg); (fun reg -> Then reg); @@ -560,10 +552,8 @@ let is_kwd = function | Entrypoint _ | For _ | Function _ -| Storage _ | Type _ | Of _ -| Operations _ | Var _ | End _ | Then _ diff --git a/ParToken.mly b/ParToken.mly index d8436e0dd..54df7f5fa 100644 --- a/ParToken.mly +++ b/ParToken.mly @@ -55,10 +55,8 @@ %token Entrypoint (* "entrypoint" *) %token For (* "for" *) %token Function (* "function" *) -%token Storage (* "storage" *) %token Type (* "type" *) %token Of (* "of" *) -%token Operations (* "operations" *) %token Var (* "var" *) %token End (* "end" *) %token Then (* "then" *) diff --git a/Parser.mly b/Parser.mly index 0c976d484..d6b85f88c 100644 --- a/Parser.mly +++ b/Parser.mly @@ -110,42 +110,8 @@ program: declaration: type_decl { TypeDecl $1 } | const_decl { ConstDecl $1 } -| storage_decl { StorageDecl $1 } -| operations_decl { OpDecl $1 } | lambda_decl { LambdaDecl $1 } -storage_decl: - Storage var COLON type_expr option(SEMI) { - let stop = - match $5 with - Some region -> region - | None -> type_expr_to_region $4 in - let region = cover $1 stop in - let value = { - kwd_storage = $1; - name = $2; - colon = $3; - store_type = $4; - terminator = $5} - in {region; value} - } - -operations_decl: - Operations var COLON type_expr option(SEMI) { - let stop = - match $5 with - Some region -> region - | None -> type_expr_to_region $4 in - let region = cover $1 stop in - let value = { - kwd_operations = $1; - name = $2; - colon = $3; - op_type = $4; - terminator = $5} - in {region; value} - } - (* Type declarations *) type_decl: @@ -252,6 +218,31 @@ fun_decl: in {region; value} } +entry_decl: + Entrypoint fun_name parameters COLON type_expr Is + seq(local_decl) + block + With expr option(SEMI) { + let stop = + match $11 with + Some region -> region + | None -> expr_to_region $10 in + let region = cover $1 stop in + let value = { + kwd_entrypoint = $1; + name = $2; + param = $3; + colon = $4; + ret_type = $5; + kwd_is = $6; + local_decls = $7; + block = $8; + kwd_with = $9; + return = $10; + terminator = $11} + in {region; value} + } + proc_decl: Procedure fun_name parameters Is seq(local_decl) @@ -273,27 +264,6 @@ proc_decl: in {region; value} } -entry_decl: - Entrypoint fun_name parameters Is - seq(local_decl) - block option(SEMI) - { - let stop = - match $7 with - Some region -> region - | None -> $6.region in - let region = cover $1 stop in - let value = { - kwd_entrypoint = $1; - name = $2; - param = $3; - kwd_is = $4; - local_decls = $5; - block = $6; - terminator = $7} - in {region; value} - } - parameters: par(nsepseq(param_decl,SEMI)) { $1 } diff --git a/Tests/a.li b/Tests/a.li index 18b153ab1..f618a5417 100644 --- a/Tests/a.li +++ b/Tests/a.li @@ -1,11 +1,9 @@ type t is int * string type u is t type v is record foo: key; bar: mutez; baz: address end -type w is K of (U of int) (*v * u*) +type w is K of (U of int) // v * u -storage s : w // Line comment type i is int; -operations o : u; const x : v = record @@ -16,7 +14,8 @@ const x : v = (* Block comment *) -entrypoint g (const l : list (int)) is +entrypoint g (var s : storage; const l : list (int)) + : operation (list) is var m : map (int, string) := empty_map; var y : v := copy x with record bar = 7 end; @@ -37,4 +36,4 @@ entrypoint g (const l : list (int)) is g (Unit); fail "in extremis" end - end + end with ([]: operation (list))