Ported to constant declaration the work done for variable declarations.

That is to say, now constants can include unannotated empty lists etc.
This commit is contained in:
Christian Rinderknecht 2019-03-20 10:06:33 +01:00
parent 563bc59285
commit 0768f0c27d
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
3 changed files with 47 additions and 40 deletions

View File

@ -13,8 +13,8 @@ open AST
(* Entry points *) (* Entry points *)
%start program interactive_expr %start contract interactive_expr
%type <AST.t> program %type <AST.t> contract
%type <AST.expr> interactive_expr %type <AST.expr> interactive_expr
%% %%
@ -129,7 +129,7 @@ sepseq(X,Sep):
(* Main *) (* Main *)
program: contract:
nseq(declaration) EOF { nseq(declaration) EOF {
{decl = $1; eof = $2} {decl = $1; eof = $2}
} }
@ -358,40 +358,21 @@ local_decl:
| const_decl { LocalConst $1 } | const_decl { LocalConst $1 }
| var_decl { LocalVar $1 } | var_decl { LocalVar $1 }
const_decl: unqualified_decl:
Const var COLON type_expr EQUAL expr option(SEMI) { var COLON type_expr EQUAL extended_expr option(SEMI) {
let stop = let stop = match $6 with
match $7 with Some region -> region
Some region -> region | None -> $5.region in
| None -> expr_to_region $6 in
let region = cover $1 stop in
let value = {
kwd_const = $1;
name = $2;
colon = $3;
const_type = $4;
equal = $5;
init = $6;
terminator = $7}
in {region; value}
}
var_decl:
Var var COLON type_expr ASS extended_expr option(SEMI) {
let stop = match $7 with
Some region -> region
| None -> $6.region in
let region = cover $1 stop in
let init = let init =
match $6.value with match $5.value with
`Expr e -> e `Expr e -> e
| `EList (lbracket, rbracket) -> | `EList (lbracket, rbracket) ->
let region = $6.region let region = $5.region
and value = { and value = {
lbracket; lbracket;
rbracket; rbracket;
colon = Region.ghost; colon = Region.ghost;
list_type = $4} in list_type = $3} in
let value = { let value = {
lpar = Region.ghost; lpar = Region.ghost;
inside = value; inside = value;
@ -403,19 +384,43 @@ var_decl:
inside = { inside = {
c_None = region; c_None = region;
colon = Region.ghost; colon = Region.ghost;
opt_type = $4}; opt_type = $3};
rpar = Region.ghost} rpar = Region.ghost}
in ConstrExpr (NoneExpr {region; value}) in in ConstrExpr (NoneExpr {region; value})
(* | `EMap inj ->*) (* | `EMap inj ->
MapExpr ( ) *)
in $1, $2, $3, $4, init, $6, stop
}
const_decl:
Const unqualified_decl {
let name, colon, const_type, equal,
init, terminator, stop = $2 in
let region = cover $1 stop in
let value = { let value = {
kwd_var = $1; kwd_const = $1;
name = $2; name;
colon = $3; colon;
var_type = $4; const_type;
assign = $5; equal;
init; init;
terminator = $7} terminator}
in {region; value}
}
var_decl:
Var unqualified_decl {
let name, colon, var_type, assign,
init, terminator, stop = $2 in
let region = cover $1 stop in
let value = {
kwd_var = $1;
name;
colon;
var_type;
assign;
init;
terminator}
in {region; value} in {region; value}
} }

View File

@ -85,7 +85,7 @@ let tokeniser = read ~log
let () = let () =
try try
let ast = Parser.program tokeniser buffer in let ast = Parser.contract tokeniser buffer in
if Utils.String.Set.mem "ast" EvalOpt.verbose if Utils.String.Set.mem "ast" EvalOpt.verbose
then AST.print_tokens ast then AST.print_tokens ast
with with

View File

@ -6,6 +6,8 @@ type store is
funded : bool funded : bool
end end
const foo : store = map "X" -> 10; "Y" -> 11 end
entrypoint contribute (storage store : store; entrypoint contribute (storage store : store;
const sender : address; const sender : address;
const amount : mutez) const amount : mutez)