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