From 0d98252fa045dd6c39b15af765f395699d11df25 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 1 Apr 2019 14:51:07 +0200 Subject: [PATCH] Added alternate syntax for record types, with brackets. New syntax: record [...] --- src/ligo/ligo-parser/AST.ml | 22 ++++---------------- src/ligo/ligo-parser/AST.mli | 11 ++-------- src/ligo/ligo-parser/Parser.mly | 15 ++++++++++--- src/ligo/ligo-parser/Tests/crowdfunding.ligo | 4 ++-- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/ligo/ligo-parser/AST.ml b/src/ligo/ligo-parser/AST.ml index 44be4d4f2..9c1952551 100644 --- a/src/ligo/ligo-parser/AST.ml +++ b/src/ligo/ligo-parser/AST.ml @@ -191,7 +191,7 @@ and type_decl = { and type_expr = TProd of cartesian | TSum of (variant reg, vbar) nsepseq reg -| TRecord of record_type reg +| TRecord of record_type | TApp of (type_name * type_tuple) reg | TPar of type_expr par reg | TAlias of variable @@ -204,14 +204,7 @@ and variant = { product : cartesian } -and record_type = { - opening : kwd_record; - field_decls : field_decls; - terminator : semi option; - closing : kwd_end -} - -and field_decls = (field_decl reg, semi) nsepseq +and record_type = field_decl reg injection reg and field_decl = { field_name : field_name; @@ -932,12 +925,8 @@ and print_variant {value; _} = and print_sum_type {value; _} = print_nsepseq "|" print_variant value -and print_record_type {value; _} = - let {opening; field_decls; terminator; closing} = value in - print_token opening "record"; - print_field_decls field_decls; - print_terminator terminator; - print_token closing "end" +and print_record_type record_type = + print_injection "record" print_field_decl record_type and print_type_app {value; _} = let type_name, type_tuple = value in @@ -950,9 +939,6 @@ and print_par_type {value; _} = print_type_expr inside; print_token rpar ")" -and print_field_decls sequence = - print_nsepseq ";" print_field_decl sequence - and print_field_decl {value; _} = let {field_name; colon; field_type} = value in print_var field_name; diff --git a/src/ligo/ligo-parser/AST.mli b/src/ligo/ligo-parser/AST.mli index 479a9f2c8..fa319c035 100644 --- a/src/ligo/ligo-parser/AST.mli +++ b/src/ligo/ligo-parser/AST.mli @@ -175,7 +175,7 @@ and type_decl = { and type_expr = TProd of cartesian | TSum of (variant reg, vbar) nsepseq reg -| TRecord of record_type reg +| TRecord of record_type | TApp of (type_name * type_tuple) reg | TPar of type_expr par reg | TAlias of variable @@ -188,14 +188,7 @@ and variant = { product : cartesian } -and record_type = { - opening : kwd_record; - field_decls : field_decls; - terminator : semi option; - closing : kwd_end -} - -and field_decls = (field_decl reg, semi) nsepseq +and record_type = field_decl reg injection reg and field_decl = { field_name : field_name; diff --git a/src/ligo/ligo-parser/Parser.mly b/src/ligo/ligo-parser/Parser.mly index dc4b56d26..75bea0049 100644 --- a/src/ligo/ligo-parser/Parser.mly +++ b/src/ligo/ligo-parser/Parser.mly @@ -205,10 +205,19 @@ record_type: let first, (others, terminator, closing) = $2 in let region = cover $1 closing and value = { - opening = $1; - field_decls = first, others; + opening = Kwd $1; + elements = Some (first, others); terminator; - closing} + closing = End closing} + in {region; value}} +| Record LBRACKET series(field_decl,RBRACKET) { + let first, (others, terminator, closing) = $3 in + let region = cover $1 closing + and value = { + opening = KwdBracket ($1,$2); + elements = Some (first, others); + terminator; + closing = RBracket closing} in {region; value}} field_decl: diff --git a/src/ligo/ligo-parser/Tests/crowdfunding.ligo b/src/ligo/ligo-parser/Tests/crowdfunding.ligo index fb61cbc0d..34d45595a 100644 --- a/src/ligo/ligo-parser/Tests/crowdfunding.ligo +++ b/src/ligo/ligo-parser/Tests/crowdfunding.ligo @@ -1,10 +1,10 @@ type store is - record + record [ goal : nat; deadline : timestamp; backers : map (address, nat); funded : bool; - end + ] entrypoint contribute (storage store : store; const sender : address;