Removed storage and operations declarations: entry-points now take the
former and return the latter.
This commit is contained in:
parent
8e294a013c
commit
5f129d924a
53
AST.ml
53
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; _} =
|
||||
|
24
AST.mli
24
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
|
||||
}
|
||||
|
||||
|
@ -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" *)
|
||||
|
10
LexToken.mll
10
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 _
|
||||
|
@ -55,10 +55,8 @@
|
||||
%token <Region.t> Entrypoint (* "entrypoint" *)
|
||||
%token <Region.t> For (* "for" *)
|
||||
%token <Region.t> Function (* "function" *)
|
||||
%token <Region.t> Storage (* "storage" *)
|
||||
%token <Region.t> Type (* "type" *)
|
||||
%token <Region.t> Of (* "of" *)
|
||||
%token <Region.t> Operations (* "operations" *)
|
||||
%token <Region.t> Var (* "var" *)
|
||||
%token <Region.t> End (* "end" *)
|
||||
%token <Region.t> Then (* "then" *)
|
||||
|
80
Parser.mly
80
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 }
|
||||
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user