diff --git a/src/passes/1-parser/cameligo/ParserAPI.ml b/src/passes/1-parser/cameligo/ParserAPI.ml index 24f663d90..df82173a9 100644 --- a/src/passes/1-parser/cameligo/ParserAPI.ml +++ b/src/passes/1-parser/cameligo/ParserAPI.ml @@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken) (* Errors *) - let format_error ?(offsets=true) mode (message, valid_opt, invalid) = - let invalid_lexeme = LexToken.to_lexeme invalid in + let format_error ?(offsets=true) mode (msg, valid_opt, invalid) = let invalid_region = LexToken.to_region invalid in let header = - "Parse error " ^ - invalid_region#to_string ~offsets mode in - let after = + "Parse error " ^ invalid_region#to_string ~offsets mode in + let trailer = match valid_opt with - None -> "," + None -> + if LexToken.is_eof invalid then "" + else let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf ", before \"%s\"" invalid_lexeme | Some valid -> - let valid_lexeme = LexToken.to_lexeme valid - in Printf.sprintf ", after \"%s\" and" valid_lexeme in - let header = header ^ after in - let before = Printf.sprintf " before \"%s\"" invalid_lexeme in - let header = header ^ before in - header ^ (if message = "" then ".\n" else ":\n" ^ message) + let valid_lexeme = LexToken.to_lexeme valid in + let s = Printf.sprintf ", after \"%s\"" valid_lexeme in + if LexToken.is_eof invalid then s + else + let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in + let header = header ^ trailer in + header ^ (if msg = "" then ".\n" else ":\n" ^ msg) end diff --git a/src/passes/1-parser/pascaligo/ParserAPI.ml b/src/passes/1-parser/pascaligo/ParserAPI.ml index 5a91be8f7..df82173a9 100644 --- a/src/passes/1-parser/pascaligo/ParserAPI.ml +++ b/src/passes/1-parser/pascaligo/ParserAPI.ml @@ -4,7 +4,7 @@ module Make (Lexer: Lexer.S with module Token := LexToken) (Parser: module type of Parser) - (ParErr: module type of ParErr) = + (ParErr: sig val message : int -> string end) = struct module I = Parser.MenhirInterpreter module S = MenhirLib.General (* Streams *) @@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken) (* Errors *) - let format_error ?(offsets=true) mode (message, valid_opt, invalid) = - let invalid_lexeme = LexToken.to_lexeme invalid in + let format_error ?(offsets=true) mode (msg, valid_opt, invalid) = let invalid_region = LexToken.to_region invalid in let header = - "Parse error " ^ - invalid_region#to_string ~offsets mode in - let after = + "Parse error " ^ invalid_region#to_string ~offsets mode in + let trailer = match valid_opt with - None -> "," + None -> + if LexToken.is_eof invalid then "" + else let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf ", before \"%s\"" invalid_lexeme | Some valid -> - let valid_lexeme = LexToken.to_lexeme valid - in Printf.sprintf ", after \"%s\" and" valid_lexeme in - let header = header ^ after in - let before = Printf.sprintf " before \"%s\"" invalid_lexeme in - let header = header ^ before in - header ^ (if message = "" then ".\n" else ":\n" ^ message) + let valid_lexeme = LexToken.to_lexeme valid in + let s = Printf.sprintf ", after \"%s\"" valid_lexeme in + if LexToken.is_eof invalid then s + else + let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in + let header = header ^ trailer in + header ^ (if msg = "" then ".\n" else ":\n" ^ msg) end diff --git a/src/passes/1-parser/reasonligo/LexToken.mli b/src/passes/1-parser/reasonligo/LexToken.mli index 7c438ba02..b5fc9e74d 100644 --- a/src/passes/1-parser/reasonligo/LexToken.mli +++ b/src/passes/1-parser/reasonligo/LexToken.mli @@ -65,7 +65,7 @@ type t = (* Comparisons *) | EQ of Region.t (* "=" *) -| EQEQ of Region.t (* "=" *) +| EQEQ of Region.t (* "==" *) | NE of Region.t (* "!=" *) | LT of Region.t (* "<" *) | GT of Region.t (* ">" *) diff --git a/src/passes/1-parser/reasonligo/ParserAPI.ml b/src/passes/1-parser/reasonligo/ParserAPI.ml index 24f663d90..df82173a9 100644 --- a/src/passes/1-parser/reasonligo/ParserAPI.ml +++ b/src/passes/1-parser/reasonligo/ParserAPI.ml @@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken) (* Errors *) - let format_error ?(offsets=true) mode (message, valid_opt, invalid) = - let invalid_lexeme = LexToken.to_lexeme invalid in + let format_error ?(offsets=true) mode (msg, valid_opt, invalid) = let invalid_region = LexToken.to_region invalid in let header = - "Parse error " ^ - invalid_region#to_string ~offsets mode in - let after = + "Parse error " ^ invalid_region#to_string ~offsets mode in + let trailer = match valid_opt with - None -> "," + None -> + if LexToken.is_eof invalid then "" + else let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf ", before \"%s\"" invalid_lexeme | Some valid -> - let valid_lexeme = LexToken.to_lexeme valid - in Printf.sprintf ", after \"%s\" and" valid_lexeme in - let header = header ^ after in - let before = Printf.sprintf " before \"%s\"" invalid_lexeme in - let header = header ^ before in - header ^ (if message = "" then ".\n" else ":\n" ^ message) + let valid_lexeme = LexToken.to_lexeme valid in + let s = Printf.sprintf ", after \"%s\"" valid_lexeme in + if LexToken.is_eof invalid then s + else + let invalid_lexeme = LexToken.to_lexeme invalid in + Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in + let header = header ^ trailer in + header ^ (if msg = "" then ".\n" else ":\n" ^ msg) end