Merge branch 'reasonligo-record-improvement' into 'dev'

Add support for record expressions of only one field.

See merge request ligolang/ligo!553
This commit is contained in:
Christian Rinderknecht 2020-04-14 11:01:11 +00:00
commit f8c16e5764
4 changed files with 171 additions and 190 deletions

View File

@ -21,7 +21,6 @@ type 'a record_elements = {
type 'a sequence_or_record =
PaSequence of 'a sequence_elements
| PaRecord of 'a record_elements
| PaSingleExpr of expr
let (<@) f g x = f (g x)
@ -913,18 +912,26 @@ expr_with_let_expr:
expr { $1 }
| let_expr(expr_with_let_expr) { $1 }
more_field_assignments:
"," sep_or_term_list(field_assignment_punning,",") {
let elts, _region = $2 in
$1, elts
}
sequence_or_record_in:
expr_with_let_expr ";" sep_or_term_list(expr_with_let_expr,";") {
let elts, _region = $3 in
let s_elts = Utils.nsepseq_cons $1 $2 elts
in PaSequence {s_elts; s_terminator=None}
sep_or_term_list(expr_with_let_expr,";") {
let elts, _region = $1 in
PaSequence {s_elts = elts; s_terminator=None}
}
| field_assignment "," sep_or_term_list(field_assignment,",") {
let elts, _region = $3 in
let r_elts = Utils.nsepseq_cons $1 $2 elts
in PaRecord {r_elts; r_terminator = None}
| field_assignment more_field_assignments? {
match $2 with
| Some (comma, elts) ->
let r_elts = Utils.nsepseq_cons $1 comma elts in
PaRecord {r_elts; r_terminator = None}
| None ->
PaRecord {r_elts = ($1, []); r_terminator = None}
}
| expr_with_let_expr ";"? { PaSingleExpr $1 }
sequence_or_record:
"{" sequence_or_record_in "}" {
@ -940,18 +947,25 @@ sequence_or_record:
let value = {compound;
ne_elements = r.r_elts;
terminator = r.r_terminator}
in ERecord {region; value}
| PaSingleExpr e -> e }
in ERecord {region; value}}
field_assignment:
field_name {
field_assignment_punning:
(* This can only happen with multiple fields -
one item punning does NOT work in ReasonML *)
field_name {
let value = {
field_name = $1;
assignment = ghost;
field_expr = EVar $1 }
in {$1 with value}
in
{$1 with value}
}
| field_name ":" expr {
| field_assignment {
$1
}
field_assignment:
field_name ":" expr {
let start = $1.region in
let stop = expr_to_region $3 in
let region = cover start stop in

View File

@ -1150,11 +1150,130 @@ interactive_expr: LBRACE ELLIPSIS WILD
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA Ident COLON Bytes VBAR
##
## Ends in an error in state: 477.
##
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning . [ RBRACE ]
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning . COMMA nsepseq(field_assignment_punning,COMMA) [ RBRACE ]
## nseq(__anonymous_0(field_assignment_punning,COMMA)) -> field_assignment_punning . COMMA seq(__anonymous_0(field_assignment_punning,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment_punning
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 155, spurious reduction of production call_expr_level_in -> core_expr
## In state 173, spurious reduction of production option(type_annotation_simple) ->
## In state 174, spurious reduction of production call_expr_level -> call_expr_level_in option(type_annotation_simple)
## In state 175, spurious reduction of production unary_expr_level -> call_expr_level
## In state 128, spurious reduction of production mult_expr_level -> unary_expr_level
## In state 152, spurious reduction of production add_expr_level -> mult_expr_level
## In state 183, spurious reduction of production cat_expr_level -> add_expr_level
## In state 204, spurious reduction of production comp_expr_level -> cat_expr_level
## In state 211, spurious reduction of production conj_expr_level -> comp_expr_level
## In state 218, spurious reduction of production disj_expr_level -> conj_expr_level
## In state 165, spurious reduction of production base_expr(expr) -> disj_expr_level
## In state 222, spurious reduction of production base_cond__open(expr) -> base_expr(expr)
## In state 223, spurious reduction of production expr -> base_cond__open(expr)
## In state 465, spurious reduction of production field_assignment -> Ident COLON expr
## In state 484, spurious reduction of production field_assignment_punning -> field_assignment
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA Ident COMMA Ident COLON Bytes VBAR
##
## Ends in an error in state: 481.
##
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning . [ RBRACE ]
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning . COMMA nsepseq(field_assignment_punning,COMMA) [ RBRACE ]
## seq(__anonymous_0(field_assignment_punning,COMMA)) -> field_assignment_punning . COMMA seq(__anonymous_0(field_assignment_punning,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment_punning
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 155, spurious reduction of production call_expr_level_in -> core_expr
## In state 173, spurious reduction of production option(type_annotation_simple) ->
## In state 174, spurious reduction of production call_expr_level -> call_expr_level_in option(type_annotation_simple)
## In state 175, spurious reduction of production unary_expr_level -> call_expr_level
## In state 128, spurious reduction of production mult_expr_level -> unary_expr_level
## In state 152, spurious reduction of production add_expr_level -> mult_expr_level
## In state 183, spurious reduction of production cat_expr_level -> add_expr_level
## In state 204, spurious reduction of production comp_expr_level -> cat_expr_level
## In state 211, spurious reduction of production conj_expr_level -> comp_expr_level
## In state 218, spurious reduction of production disj_expr_level -> conj_expr_level
## In state 165, spurious reduction of production base_expr(expr) -> disj_expr_level
## In state 222, spurious reduction of production base_cond__open(expr) -> base_expr(expr)
## In state 223, spurious reduction of production expr -> base_cond__open(expr)
## In state 465, spurious reduction of production field_assignment -> Ident COLON expr
## In state 484, spurious reduction of production field_assignment_punning -> field_assignment
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA Ident COMMA Ident COMMA WILD
##
## Ends in an error in state: 482.
##
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning COMMA . nsepseq(field_assignment_punning,COMMA) [ RBRACE ]
## seq(__anonymous_0(field_assignment_punning,COMMA)) -> field_assignment_punning COMMA . seq(__anonymous_0(field_assignment_punning,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment_punning COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA Ident COMMA WILD
##
## Ends in an error in state: 478.
##
## nsepseq(field_assignment_punning,COMMA) -> field_assignment_punning COMMA . nsepseq(field_assignment_punning,COMMA) [ RBRACE ]
## nseq(__anonymous_0(field_assignment_punning,COMMA)) -> field_assignment_punning COMMA . seq(__anonymous_0(field_assignment_punning,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment_punning COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA Ident WILD
##
## Ends in an error in state: 473.
##
## field_assignment -> Ident . COLON expr [ RBRACE COMMA ]
## field_assignment_punning -> Ident . [ RBRACE COMMA ]
##
## The known suffix of the stack is as follows:
## Ident
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes COMMA WILD
##
## Ends in an error in state: 472.
##
## more_field_assignments -> COMMA . sep_or_term_list(field_assignment_punning,COMMA) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COLON Bytes VBAR
##
## Ends in an error in state: 468.
## Ends in an error in state: 471.
##
## sequence_or_record_in -> field_assignment . COMMA sep_or_term_list(field_assignment,COMMA) [ RBRACE ]
## sequence_or_record_in -> field_assignment . option(more_field_assignments) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment
@ -1193,130 +1312,12 @@ interactive_expr: LBRACE Ident COLON VBAR
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA Ident COLON Bytes VBAR
##
## Ends in an error in state: 474.
##
## nsepseq(field_assignment,COMMA) -> field_assignment . [ RBRACE ]
## nsepseq(field_assignment,COMMA) -> field_assignment . COMMA nsepseq(field_assignment,COMMA) [ RBRACE ]
## nseq(__anonymous_0(field_assignment,COMMA)) -> field_assignment . COMMA seq(__anonymous_0(field_assignment,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 155, spurious reduction of production call_expr_level_in -> core_expr
## In state 173, spurious reduction of production option(type_annotation_simple) ->
## In state 174, spurious reduction of production call_expr_level -> call_expr_level_in option(type_annotation_simple)
## In state 175, spurious reduction of production unary_expr_level -> call_expr_level
## In state 128, spurious reduction of production mult_expr_level -> unary_expr_level
## In state 152, spurious reduction of production add_expr_level -> mult_expr_level
## In state 183, spurious reduction of production cat_expr_level -> add_expr_level
## In state 204, spurious reduction of production comp_expr_level -> cat_expr_level
## In state 211, spurious reduction of production conj_expr_level -> comp_expr_level
## In state 218, spurious reduction of production disj_expr_level -> conj_expr_level
## In state 165, spurious reduction of production base_expr(expr) -> disj_expr_level
## In state 222, spurious reduction of production base_cond__open(expr) -> base_expr(expr)
## In state 223, spurious reduction of production expr -> base_cond__open(expr)
## In state 465, spurious reduction of production field_assignment -> Ident COLON expr
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA Ident COMMA Ident COLON Bytes VBAR
##
## Ends in an error in state: 478.
##
## nsepseq(field_assignment,COMMA) -> field_assignment . [ RBRACE ]
## nsepseq(field_assignment,COMMA) -> field_assignment . COMMA nsepseq(field_assignment,COMMA) [ RBRACE ]
## seq(__anonymous_0(field_assignment,COMMA)) -> field_assignment . COMMA seq(__anonymous_0(field_assignment,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 155, spurious reduction of production call_expr_level_in -> core_expr
## In state 173, spurious reduction of production option(type_annotation_simple) ->
## In state 174, spurious reduction of production call_expr_level -> call_expr_level_in option(type_annotation_simple)
## In state 175, spurious reduction of production unary_expr_level -> call_expr_level
## In state 128, spurious reduction of production mult_expr_level -> unary_expr_level
## In state 152, spurious reduction of production add_expr_level -> mult_expr_level
## In state 183, spurious reduction of production cat_expr_level -> add_expr_level
## In state 204, spurious reduction of production comp_expr_level -> cat_expr_level
## In state 211, spurious reduction of production conj_expr_level -> comp_expr_level
## In state 218, spurious reduction of production disj_expr_level -> conj_expr_level
## In state 165, spurious reduction of production base_expr(expr) -> disj_expr_level
## In state 222, spurious reduction of production base_cond__open(expr) -> base_expr(expr)
## In state 223, spurious reduction of production expr -> base_cond__open(expr)
## In state 465, spurious reduction of production field_assignment -> Ident COLON expr
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA Ident COMMA Ident COMMA WILD
##
## Ends in an error in state: 479.
##
## nsepseq(field_assignment,COMMA) -> field_assignment COMMA . nsepseq(field_assignment,COMMA) [ RBRACE ]
## seq(__anonymous_0(field_assignment,COMMA)) -> field_assignment COMMA . seq(__anonymous_0(field_assignment,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA Ident COMMA WILD
##
## Ends in an error in state: 475.
##
## nsepseq(field_assignment,COMMA) -> field_assignment COMMA . nsepseq(field_assignment,COMMA) [ RBRACE ]
## nseq(__anonymous_0(field_assignment,COMMA)) -> field_assignment COMMA . seq(__anonymous_0(field_assignment,COMMA)) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA Ident WILD
##
## Ends in an error in state: 470.
##
## field_assignment -> Ident . [ RBRACE COMMA ]
## field_assignment -> Ident . COLON expr [ RBRACE COMMA ]
##
## The known suffix of the stack is as follows:
## Ident
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident COMMA WILD
##
## Ends in an error in state: 469.
##
## sequence_or_record_in -> field_assignment COMMA . sep_or_term_list(field_assignment,COMMA) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## field_assignment COMMA
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE Ident WILD
##
## Ends in an error in state: 463.
##
## common_expr -> Ident . [ TIMES SLASH SEMI RBRACE PLUS Or NE Mod MINUS LT LPAR LE GT GE EQEQ COLON CAT BOOL_OR BOOL_AND ARROW ]
## field_assignment -> Ident . [ COMMA ]
## field_assignment -> Ident . COLON expr [ COMMA ]
## field_assignment -> Ident . COLON expr [ RBRACE COMMA ]
## projection -> Ident . selection [ TIMES SLASH SEMI RBRACE PLUS Or NE Mod MINUS LT LPAR LE GT GE EQEQ COLON CAT BOOL_OR BOOL_AND ARROW ]
##
## The known suffix of the stack is as follows:
@ -1340,20 +1341,7 @@ interactive_expr: LBRACE VBAR
interactive_expr: LBRACE WILD SEMI VBAR
##
## Ends in an error in state: 482.
##
## option(SEMI) -> SEMI . [ RBRACE ]
## sequence_or_record_in -> expr_with_let_expr SEMI . sep_or_term_list(expr_with_let_expr,SEMI) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## expr_with_let_expr SEMI
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE WILD SEMI WILD SEMI VBAR
##
## Ends in an error in state: 487.
## Ends in an error in state: 488.
##
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr SEMI . nsepseq(expr_with_let_expr,SEMI) [ RBRACE ]
## nseq(__anonymous_0(expr_with_let_expr,SEMI)) -> expr_with_let_expr SEMI . seq(__anonymous_0(expr_with_let_expr,SEMI)) [ RBRACE ]
@ -1364,9 +1352,9 @@ interactive_expr: LBRACE WILD SEMI WILD SEMI VBAR
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE WILD SEMI WILD SEMI WILD SEMI VBAR
interactive_expr: LBRACE WILD SEMI WILD SEMI VBAR
##
## Ends in an error in state: 491.
## Ends in an error in state: 492.
##
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr SEMI . nsepseq(expr_with_let_expr,SEMI) [ RBRACE ]
## seq(__anonymous_0(expr_with_let_expr,SEMI)) -> expr_with_let_expr SEMI . seq(__anonymous_0(expr_with_let_expr,SEMI)) [ RBRACE ]
@ -1377,9 +1365,9 @@ interactive_expr: LBRACE WILD SEMI WILD SEMI WILD SEMI VBAR
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE WILD SEMI WILD SEMI WILD VBAR
interactive_expr: LBRACE WILD SEMI WILD VBAR
##
## Ends in an error in state: 490.
## Ends in an error in state: 491.
##
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr . [ RBRACE ]
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr . SEMI nsepseq(expr_with_let_expr,SEMI) [ RBRACE ]
@ -1410,9 +1398,9 @@ interactive_expr: LBRACE WILD SEMI WILD SEMI WILD VBAR
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE WILD SEMI WILD VBAR
interactive_expr: LBRACE WILD VBAR
##
## Ends in an error in state: 486.
## Ends in an error in state: 487.
##
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr . [ RBRACE ]
## nsepseq(expr_with_let_expr,SEMI) -> expr_with_let_expr . SEMI nsepseq(expr_with_let_expr,SEMI) [ RBRACE ]
@ -1443,38 +1431,6 @@ interactive_expr: LBRACE WILD SEMI WILD VBAR
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACE WILD VBAR
##
## Ends in an error in state: 481.
##
## sequence_or_record_in -> expr_with_let_expr . SEMI sep_or_term_list(expr_with_let_expr,SEMI) [ RBRACE ]
## sequence_or_record_in -> expr_with_let_expr . option(SEMI) [ RBRACE ]
##
## The known suffix of the stack is as follows:
## expr_with_let_expr
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 155, spurious reduction of production call_expr_level_in -> core_expr
## In state 173, spurious reduction of production option(type_annotation_simple) ->
## In state 174, spurious reduction of production call_expr_level -> call_expr_level_in option(type_annotation_simple)
## In state 175, spurious reduction of production unary_expr_level -> call_expr_level
## In state 128, spurious reduction of production mult_expr_level -> unary_expr_level
## In state 152, spurious reduction of production add_expr_level -> mult_expr_level
## In state 183, spurious reduction of production cat_expr_level -> add_expr_level
## In state 204, spurious reduction of production comp_expr_level -> cat_expr_level
## In state 211, spurious reduction of production conj_expr_level -> comp_expr_level
## In state 218, spurious reduction of production disj_expr_level -> conj_expr_level
## In state 165, spurious reduction of production base_expr(expr) -> disj_expr_level
## In state 222, spurious reduction of production base_cond__open(expr) -> base_expr(expr)
## In state 223, spurious reduction of production expr -> base_cond__open(expr)
## In state 400, spurious reduction of production expr_with_let_expr -> expr
##
<YOUR SYNTAX ERROR MESSAGE HERE>
interactive_expr: LBRACKET VBAR
##
## Ends in an error in state: 91.
@ -4149,4 +4105,5 @@ contract: WILD
##
##
<YOUR SYNTAX ERROR MESSAGE HERE>
<YOUR SYNTAX ERROR MESSAGE HERE>

View File

@ -0,0 +1,5 @@
type p = {x: int}
let o = (p: int): p => {
x: p
}

View File

@ -2328,6 +2328,10 @@ let tuple_list_religo () : unit result =
let%bind _ = retype_file "./contracts/tuple_list.religo" in
ok ()
let single_record_expr_religo () : unit result =
let%bind _ = retype_file "./contracts/single_record_item.religo" in
ok ()
let loop_bugs_ligo () : unit result =
let%bind program = type_file "./contracts/loop_bugs.ligo" in
let input = e_unit () in
@ -2515,4 +2519,5 @@ let main = test_suite "Integration (End to End)" [
test "no semicolon (religo)" no_semicolon_religo ;
test "loop_bugs (ligo)" loop_bugs_ligo ;
test "tuple_list (religo)" tuple_list_religo ;
test "single_record_expr (religo)" single_record_expr_religo ;
]