Merge branch 'rinderknecht@fix-sequences' into 'dev'

[CameLIGO] Fix parsing of sequences

See merge request ligolang/ligo!688
This commit is contained in:
Christian Rinderknecht 2020-06-22 22:58:59 +00:00
commit 77eb1335a1
6 changed files with 416 additions and 251 deletions

View File

@ -56,7 +56,6 @@ type c_Some = Region.t
type arrow = Region.t (* "->" *)
type cons = Region.t (* "::" *)
type percent = Region.t (* "%" *)
type cat = Region.t (* "^" *)
type append = Region.t (* "@" *)
type dot = Region.t (* "." *)

View File

@ -586,6 +586,12 @@ core_expr:
| par(expr) { EPar $1 }
| par(annot_expr) { EAnnot $1 }
code_inj:
"<lang>" expr "]" {
let region = cover $1.region $3
and value = {language=$1; code=$2; rbracket=$3}
in {region; value} }
annot_expr:
expr ":" type_expr { $1,$2,$3 }
@ -652,49 +658,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}
let elements = $2 in
let value = {compound; elements; terminator=None}
in {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;
@ -702,13 +700,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_inj:
"<lang>" expr "]" {
let region = cover $1.region $3
and value = {language=$1; code=$2; rbracket=$3}
in {region; value} }

View File

@ -53,7 +53,7 @@
(executable
(name ParserMain)
(libraries parser_cameligo)
(modules ParserMain)
(modules ParserMain Parser_msg)
(preprocess
(pps bisect_ppx --conditional))
(flags (:standard -open Simple_utils -open Parser_shared -open Parser_cameligo)))
@ -65,6 +65,19 @@
(deps (:script_messages ../../../../vendors/ligo-utils/simple-utils/messages.sh) Parser.mly LexToken.mli ParToken.mly)
(action (run %{script_messages} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly Parser.mly)))
(rule
(targets Parser_msg.ml)
(deps Parser.mly ParToken.mly Parser.msg)
(action
(with-stdout-to %{targets}
(bash
"menhir \
--compile-errors Parser.msg \
--external-tokens LexToken \
--base Parser \
ParToken.mly \
Parser.mly"))))
;; Build of all the LIGO source file that cover all error states
(rule
@ -74,27 +87,6 @@
;; Error messages
;; Generate error messages from scratch
; (rule
; (targets error.messages)
; (deps Parser.mly ParToken.mly error.messages.checked-in)
; (action
; (with-stdout-to %{targets}
; (bash
; "menhir \
; --unused-tokens \
; --list-errors \
; --table \
; --strict \
; --external-tokens LexToken.mli \
; --base Parser.mly \
; ParToken.mly \
; Parser.mly
; "
; )
; ))
; )
(rule
(targets error.messages)
(mode (promote (until-clean) (only *)))

File diff suppressed because it is too large Load Diff

View File

@ -66,6 +66,19 @@
(deps (:script_messages ../../../../vendors/ligo-utils/simple-utils/messages.sh) Parser.mly LexToken.mli ParToken.mly)
(action (run %{script_messages} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly Parser.mly)))
(rule
(targets Parser_msg.ml)
(deps Parser.mly ParToken.mly Parser.msg)
(action
(with-stdout-to %{targets}
(bash
"menhir \
--compile-errors Parser.msg \
--external-tokens LexToken \
--base Parser \
ParToken.mly \
Parser.mly"))))
;; Build of all the LIGO source file that cover all error states
(rule
@ -75,27 +88,6 @@
;; Error messages
;; Generate error messages from scratch
; (rule
; (targets error.messages)
; (deps Parser.mly ParToken.mly error.messages.checked-in)
; (action
; (with-stdout-to %{targets}
; (bash
; "menhir \
; --unused-tokens \
; --list-errors \
; --table \
; --strict \
; --external-tokens LexToken.mli \
; --base Parser.mly \
; ParToken.mly \
; Parser.mly
; "
; )
; ))
; )
(rule
(targets error.messages)
(mode (promote (until-clean) (only *)))
@ -155,8 +147,6 @@
)
)
(rule
(targets ParErr.ml)
(mode (promote (until-clean) (only *)))

View File

@ -65,6 +65,19 @@
(deps (:script_messages ../../../../vendors/ligo-utils/simple-utils/messages.sh) Parser.mly LexToken.mli ParToken.mly)
(action (run %{script_messages} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly Parser.mly )))
(rule
(targets Parser_msg.ml)
(deps Parser.mly ParToken.mly Parser.msg)
(action
(with-stdout-to %{targets}
(bash
"menhir \
--compile-errors Parser.msg \
--external-tokens LexToken \
--base Parser \
ParToken.mly \
Parser.mly"))))
;; Build of all the LIGO source file that cover all error states
(rule
@ -72,28 +85,6 @@
(deps (:script_cover ../../../../vendors/ligo-utils/simple-utils/cover.sh) Parser.mly LexToken.mli ParToken.mly Parser.msg Unlexer.exe)
(action (run %{script_cover} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly --ext=religo --unlexer=./Unlexer.exe --messages=Parser.msg --dir=. --concatenate Parser.mly )))
;; Error messages
;; Generate error messages from scratch
; (rule
; (targets error.messages)
; (deps Parser.mly ParToken.mly error.messages.checked-in)
; (action
; (with-stdout-to %{targets}
; (bash
; "menhir \
; --unused-tokens \
; --list-errors \
; --table \
; --strict \
; --external-tokens LexToken.mli \
; --base Parser.mly \
; ParToken.mly \
; Parser.mly
; "
; )
; ))
; )
(rule
(targets error.messages)
(mode (promote (until-clean) (only *)))