From 285be327294d7d3588fa354e4d7ef6646fec8967 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 21 Mar 2019 21:34:22 +0100 Subject: [PATCH] I added an optional semi-colon in record type declarations. --- AST.ml | 16 +++++++++------- AST.mli | 7 ++++--- AST2.ml | 6 +++--- Parser.mly | 14 ++++++++------ Tests/{a.li => a.ligo} | 0 Tests/crowdfunding.ligo | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) rename Tests/{a.li => a.ligo} (100%) diff --git a/AST.ml b/AST.ml index dbb2762af..111550bf5 100644 --- a/AST.ml +++ b/AST.ml @@ -196,9 +196,10 @@ and variant = { } and record_type = { - kwd_record : kwd_record; - fields : field_decls; - kwd_end : kwd_end + opening : kwd_record; + field_decls : field_decls; + terminator : semi option; + close : kwd_end } and field_decls = (field_decl reg, semi) nsepseq @@ -833,10 +834,11 @@ and print_sum_type {value; _} = print_nsepseq "|" print_variant value and print_record_type {value; _} = - let {kwd_record; fields; kwd_end} = value in - print_token kwd_record "record"; - print_field_decls fields; - print_token kwd_end "end" + let {opening; field_decls; terminator; close} = value in + print_token opening "record"; + print_field_decls field_decls; + print_terminator terminator; + print_token close "end" and print_type_app {value; _} = let type_name, type_tuple = value in diff --git a/AST.mli b/AST.mli index cdef34eba..0ca9d2fa4 100644 --- a/AST.mli +++ b/AST.mli @@ -180,9 +180,10 @@ and variant = { } and record_type = { - kwd_record : kwd_record; - fields : field_decls; - kwd_end : kwd_end + opening : kwd_record; + field_decls : field_decls; + terminator : semi option; + close : kwd_end } and field_decls = (field_decl reg, semi) nsepseq diff --git a/AST2.ml b/AST2.ml index c09011c9c..78a181f79 100644 --- a/AST2.ml +++ b/AST2.ml @@ -18,7 +18,7 @@ module O = struct PVar of var_name | PWild | PInt of Z.t - | PBytes of Hex.t + | PBytes of MBytes.t | PString of string | PUnit | PFalse @@ -81,7 +81,7 @@ module O = struct and constant = Unit - | Int of Z.t | String of string | Bytes of Hex.t + | Int of Z.t | String of string | Bytes of MBytes.t | False | True | Null of type_expr | EmptySet of type_expr @@ -654,7 +654,7 @@ let s_ast (ast : I.ast) : O.ast = (* and s_bytes {region; value = lexeme, abstract} = *) (* printf "%s: Bytes (\"%s\", \"0x%s\")\n" *) (* (compact region) lexeme *) -(* (Hex.to_string abstract) *) +(* (MBytes.to_hex abstract |> Hex.to_string) *) (* and s_int {region; value = lexeme, abstract} = *) (* printf "%s: Int (\"%s\", %s)\n" *) diff --git a/Parser.mly b/Parser.mly index 75520bd90..b8a582c0d 100644 --- a/Parser.mly +++ b/Parser.mly @@ -201,12 +201,14 @@ variant: } record_type: - Record - nsepseq(field_decl,SEMI) - End - { - let region = cover $1 $3 - and value = {kwd_record = $1; fields = $2; kwd_end = $3} + Record series(field_decl) { + let first, (others, terminator, close) = $2 in + let region = cover $1 close + and value = { + opening = $1; + field_decls = first, others; + terminator; + close} in {region; value} } diff --git a/Tests/a.li b/Tests/a.ligo similarity index 100% rename from Tests/a.li rename to Tests/a.ligo diff --git a/Tests/crowdfunding.ligo b/Tests/crowdfunding.ligo index c1a909f3a..5002e0549 100644 --- a/Tests/crowdfunding.ligo +++ b/Tests/crowdfunding.ligo @@ -3,7 +3,7 @@ type store is goal : nat; deadline : timestamp; backers : map (address, nat); - funded : bool + funded : bool; end const foo : store = map "X" -> 10; "Y" -> 11 end