I added an optional semi-colon in record type declarations.

This commit is contained in:
Christian Rinderknecht 2019-03-21 21:34:22 +01:00
parent fa8adb9bde
commit 285be32729
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
6 changed files with 25 additions and 20 deletions

16
AST.ml
View File

@ -196,9 +196,10 @@ and variant = {
} }
and record_type = { and record_type = {
kwd_record : kwd_record; opening : kwd_record;
fields : field_decls; field_decls : field_decls;
kwd_end : kwd_end terminator : semi option;
close : kwd_end
} }
and field_decls = (field_decl reg, semi) nsepseq and field_decls = (field_decl reg, semi) nsepseq
@ -833,10 +834,11 @@ and print_sum_type {value; _} =
print_nsepseq "|" print_variant value print_nsepseq "|" print_variant value
and print_record_type {value; _} = and print_record_type {value; _} =
let {kwd_record; fields; kwd_end} = value in let {opening; field_decls; terminator; close} = value in
print_token kwd_record "record"; print_token opening "record";
print_field_decls fields; print_field_decls field_decls;
print_token kwd_end "end" print_terminator terminator;
print_token close "end"
and print_type_app {value; _} = and print_type_app {value; _} =
let type_name, type_tuple = value in let type_name, type_tuple = value in

View File

@ -180,9 +180,10 @@ and variant = {
} }
and record_type = { and record_type = {
kwd_record : kwd_record; opening : kwd_record;
fields : field_decls; field_decls : field_decls;
kwd_end : kwd_end terminator : semi option;
close : kwd_end
} }
and field_decls = (field_decl reg, semi) nsepseq and field_decls = (field_decl reg, semi) nsepseq

View File

@ -18,7 +18,7 @@ module O = struct
PVar of var_name PVar of var_name
| PWild | PWild
| PInt of Z.t | PInt of Z.t
| PBytes of Hex.t | PBytes of MBytes.t
| PString of string | PString of string
| PUnit | PUnit
| PFalse | PFalse
@ -81,7 +81,7 @@ module O = struct
and constant = and constant =
Unit 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 | False | True
| Null of type_expr | Null of type_expr
| EmptySet 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} = *) (* and s_bytes {region; value = lexeme, abstract} = *)
(* printf "%s: Bytes (\"%s\", \"0x%s\")\n" *) (* printf "%s: Bytes (\"%s\", \"0x%s\")\n" *)
(* (compact region) lexeme *) (* (compact region) lexeme *)
(* (Hex.to_string abstract) *) (* (MBytes.to_hex abstract |> Hex.to_string) *)
(* and s_int {region; value = lexeme, abstract} = *) (* and s_int {region; value = lexeme, abstract} = *)
(* printf "%s: Int (\"%s\", %s)\n" *) (* printf "%s: Int (\"%s\", %s)\n" *)

View File

@ -201,12 +201,14 @@ variant:
} }
record_type: record_type:
Record Record series(field_decl) {
nsepseq(field_decl,SEMI) let first, (others, terminator, close) = $2 in
End let region = cover $1 close
{ and value = {
let region = cover $1 $3 opening = $1;
and value = {kwd_record = $1; fields = $2; kwd_end = $3} field_decls = first, others;
terminator;
close}
in {region; value} in {region; value}
} }

View File

@ -3,7 +3,7 @@ type store is
goal : nat; goal : nat;
deadline : timestamp; deadline : timestamp;
backers : map (address, nat); backers : map (address, nat);
funded : bool funded : bool;
end end
const foo : store = map "X" -> 10; "Y" -> 11 end const foo : store = map "X" -> 10; "Y" -> 11 end