diff --git a/src/passes/1-parser/cameligo.ml b/src/passes/1-parser/cameligo.ml index 859f4ccd1..53ecdc29e 100644 --- a/src/passes/1-parser/cameligo.ml +++ b/src/passes/1-parser/cameligo.ml @@ -33,15 +33,22 @@ module Errors = struct file in let message () = str in - let loc = Region.make - ~start:(Pos.from_byte start) - ~stop:(Pos.from_byte end_) + let loc = if start.pos_cnum = -1 then + Region.make + ~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 - let data = [ - ("parser_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ loc - ) - ] in error ~data title message let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf = diff --git a/src/passes/1-parser/pascaligo.ml b/src/passes/1-parser/pascaligo.ml index 7218acfa4..4858fd0a4 100644 --- a/src/passes/1-parser/pascaligo.ml +++ b/src/passes/1-parser/pascaligo.ml @@ -61,16 +61,23 @@ module Errors = struct end_.pos_lnum (end_.pos_cnum - end_.pos_bol) file in - let message () = str in - let loc = Region.make - ~start:(Pos.from_byte start) - ~stop:(Pos.from_byte end_) + let message () = str in + let loc = if start.pos_cnum = -1 then + Region.make + ~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 - let data = [ - ("parser_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ loc - ) - ] in error ~data title message let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf = diff --git a/src/passes/1-parser/reasonligo.ml b/src/passes/1-parser/reasonligo.ml index 7bb7ab0cf..c919ef399 100644 --- a/src/passes/1-parser/reasonligo.ml +++ b/src/passes/1-parser/reasonligo.ml @@ -44,15 +44,22 @@ module Errors = struct file in let message () = str in - let loc = Region.make - ~start:(Pos.from_byte start) - ~stop:(Pos.from_byte end_) + let loc = if start.pos_cnum = -1 then + Region.make + ~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 - let data = [ - ("location", - fun () -> Format.asprintf "%a" Location.pp_lift @@ loc - ) - ] in error ~data title message let unrecognized_error source (start: Lexing.position) (end_: Lexing.position) lexbuf =