Merge branch 'fix-negative-pos-error' into 'dev'

Improve error handling of negative start positions.

See merge request ligolang/ligo!321
This commit is contained in:
Rémi Lesenechal 2020-01-09 11:33:21 +00:00
commit 3cfbd60cd2
3 changed files with 46 additions and 25 deletions

View File

@ -33,15 +33,22 @@ module Errors = struct
file file
in in
let message () = str in let message () = str in
let loc = Region.make let loc = if start.pos_cnum = -1 then
~start:(Pos.from_byte start) Region.make
~stop:(Pos.from_byte end_) ~start: Pos.min
~stop:(Pos.from_byte end_)
else
Region.make
~start:(Pos.from_byte start)
~stop:(Pos.from_byte end_)
in
let data =
[
("parser_loc",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
]
in in
let data = [
("parser_loc",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
] in
error ~data title message error ~data title message
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf = let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =

View File

@ -61,16 +61,23 @@ module Errors = struct
end_.pos_lnum (end_.pos_cnum - end_.pos_bol) end_.pos_lnum (end_.pos_cnum - end_.pos_bol)
file file
in in
let message () = str in let message () = str in
let loc = Region.make let loc = if start.pos_cnum = -1 then
~start:(Pos.from_byte start) Region.make
~stop:(Pos.from_byte end_) ~start: Pos.min
~stop:(Pos.from_byte end_)
else
Region.make
~start:(Pos.from_byte start)
~stop:(Pos.from_byte end_)
in
let data =
[
("parser_loc",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
]
in in
let data = [
("parser_loc",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
] in
error ~data title message error ~data title message
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf = let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =

View File

@ -44,15 +44,22 @@ module Errors = struct
file file
in in
let message () = str in let message () = str in
let loc = Region.make let loc = if start.pos_cnum = -1 then
~start:(Pos.from_byte start) Region.make
~stop:(Pos.from_byte end_) ~start: Pos.min
~stop:(Pos.from_byte end_)
else
Region.make
~start:(Pos.from_byte start)
~stop:(Pos.from_byte end_)
in
let data =
[
("parser_loc",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
]
in in
let data = [
("location",
fun () -> Format.asprintf "%a" Location.pp_lift @@ loc
)
] in
error ~data title message error ~data title message
let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf = let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =