Fixed the parsing of sequences in CameLIGO.

This commit is contained in:
Christian Rinderknecht 2020-06-20 15:49:52 +02:00
parent 027f73fa01
commit 8ce7ae0f27
2 changed files with 387 additions and 195 deletions

View File

@ -121,11 +121,10 @@ type_decl:
"type" type_name "=" type_expr { "type" type_name "=" type_expr {
Scoping.check_reserved_name $2; Scoping.check_reserved_name $2;
let region = cover $1 (type_expr_to_region $4) in let region = cover $1 (type_expr_to_region $4) in
let value = { let value = {kwd_type = $1;
kwd_type = $1; name = $2;
name = $2; eq = $3;
eq = $3; type_expr = $4}
type_expr = $4}
in {region; value} } in {region; value} }
type_expr: type_expr:
@ -580,13 +579,24 @@ core_expr:
| "false" { ELogic (BoolExpr (False $1)) } | "false" { ELogic (BoolExpr (False $1)) }
| "true" { ELogic (BoolExpr (True $1)) } | "true" { ELogic (BoolExpr (True $1)) }
| list__(expr) { EList (EListComp $1) } | list__(expr) { EList (EListComp $1) }
| sequence { ESeq $1 } | sequence { $1 }
| record_expr { ERecord $1 } | record_expr { ERecord $1 }
| update_record { EUpdate $1 } | update_record { EUpdate $1 }
| code_insert { ECodeInsert $1 } | code_insert { ECodeInsert $1 }
| par(expr) { EPar $1 } | par(expr) { EPar $1 }
| par(annot_expr) { EAnnot $1 } | par(annot_expr) { EAnnot $1 }
code_insert:
"[" "%" Constr expr "]" {
let region = cover $1 $5 in
let value = {
lbracket =$1;
percent =$2;
language =$3;
code =$4;
rbracket =$5}
in {region; value} }
annot_expr: annot_expr:
expr ":" type_expr { $1,$2,$3 } expr ":" type_expr { $1,$2,$3 }
@ -653,49 +663,41 @@ field_path_assignment :
field_assignment: field_assignment:
field_name "=" expr { field_name "=" expr {
let region = cover $1.region (expr_to_region $3) let region = cover $1.region (expr_to_region $3)
and value = {field_name = $1; and value = {field_name=$1; assignment=$2; field_expr=$3}
assignment = $2;
field_expr = $3}
in {region; value} } in {region; value} }
path : path :
"<ident>" { Name $1 } "<ident>" { Name $1 }
| projection { Path $1 } | projection { Path $1 }
(* Sequences *)
sequence: sequence:
"begin" series? "end" { "begin" series? "end" {
let region = cover $1 $3 let region = cover $1 $3
and compound = BeginEnd ($1,$3) in and compound = BeginEnd ($1,$3) in
let elements, terminator = let elements = $2 in
match $2 with let value = {compound; elements; terminator=None}
None -> None, None in ESeq {region; value} }
| Some (ne_elements, terminator) ->
Some ne_elements, terminator in
let value = {compound; elements; terminator}
in {region; value} }
series: series:
last_expr { seq_expr ";" series { Utils.nsepseq_cons $1 $2 $3 }
let expr, term = $1 in (expr, []), term | last_expr { $1,[] }
}
| seq_expr ";" series {
let rest, term = $3 in
let seq = Utils.nsepseq_cons $1 $2 rest
in seq, term }
last_expr: last_expr:
seq_expr ";"? seq_expr
| fun_expr(seq_expr) ";"? | fun_expr(last_expr)
| match_expr(seq_expr) ";"? { | match_expr(last_expr)
$1,$2 | let_in_sequence { $1 }
}
| "let" ioption("rec") let_binding seq(Attr) "in" series { let_in_sequence:
let seq, term = $6 in "let" ioption("rec") let_binding seq(Attr) "in" series {
let seq = $6 in
let stop = nsepseq_to_region expr_to_region seq in let stop = nsepseq_to_region expr_to_region seq in
let region = cover $1 stop in let region = cover $1 stop in
let compound = BeginEnd (Region.ghost, Region.ghost) in let compound = BeginEnd (Region.ghost, Region.ghost) in
let elements = Some seq in let elements = Some seq in
let value = {compound; elements; terminator=term} in let value = {compound; elements; terminator=None} in
let body = ESeq {region; value} in let body = ESeq {region; value} in
let value = {kwd_let = $1; let value = {kwd_let = $1;
kwd_rec = $2; kwd_rec = $2;
@ -703,18 +705,7 @@ last_expr:
attributes = $4; attributes = $4;
kwd_in = $5; kwd_in = $5;
body} body}
in ELetIn {region; value}, term } in ELetIn {region; value} }
seq_expr: seq_expr:
disj_expr_level | if_then_else (seq_expr) { $1 } disj_expr_level | if_then_else (seq_expr) { $1 }
code_insert:
"[" "%" Constr expr "]" {
let region = cover $1 $5 in
let value = {
lbracket =$1;
percent =$2;
language =$3;
code =$4;
rbracket =$5}
in {region; value} }

File diff suppressed because it is too large Load Diff