Handling of EOF in ParserAPI messages.
This commit is contained in:
parent
345ffe22e4
commit
c18e6e9748
@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken)
|
|||||||
|
|
||||||
(* Errors *)
|
(* Errors *)
|
||||||
|
|
||||||
let format_error ?(offsets=true) mode (message, valid_opt, invalid) =
|
let format_error ?(offsets=true) mode (msg, valid_opt, invalid) =
|
||||||
let invalid_lexeme = LexToken.to_lexeme invalid in
|
|
||||||
let invalid_region = LexToken.to_region invalid in
|
let invalid_region = LexToken.to_region invalid in
|
||||||
let header =
|
let header =
|
||||||
"Parse error " ^
|
"Parse error " ^ invalid_region#to_string ~offsets mode in
|
||||||
invalid_region#to_string ~offsets mode in
|
let trailer =
|
||||||
let after =
|
|
||||||
match valid_opt with
|
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 ->
|
| Some valid ->
|
||||||
let valid_lexeme = LexToken.to_lexeme valid
|
let valid_lexeme = LexToken.to_lexeme valid in
|
||||||
in Printf.sprintf ", after \"%s\" and" valid_lexeme in
|
let s = Printf.sprintf ", after \"%s\"" valid_lexeme in
|
||||||
let header = header ^ after in
|
if LexToken.is_eof invalid then s
|
||||||
let before = Printf.sprintf " before \"%s\"" invalid_lexeme in
|
else
|
||||||
let header = header ^ before in
|
let invalid_lexeme = LexToken.to_lexeme invalid in
|
||||||
header ^ (if message = "" then ".\n" else ":\n" ^ message)
|
Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in
|
||||||
|
let header = header ^ trailer in
|
||||||
|
header ^ (if msg = "" then ".\n" else ":\n" ^ msg)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
module Make (Lexer: Lexer.S with module Token := LexToken)
|
module Make (Lexer: Lexer.S with module Token := LexToken)
|
||||||
(Parser: module type of Parser)
|
(Parser: module type of Parser)
|
||||||
(ParErr: module type of ParErr) =
|
(ParErr: sig val message : int -> string end) =
|
||||||
struct
|
struct
|
||||||
module I = Parser.MenhirInterpreter
|
module I = Parser.MenhirInterpreter
|
||||||
module S = MenhirLib.General (* Streams *)
|
module S = MenhirLib.General (* Streams *)
|
||||||
@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken)
|
|||||||
|
|
||||||
(* Errors *)
|
(* Errors *)
|
||||||
|
|
||||||
let format_error ?(offsets=true) mode (message, valid_opt, invalid) =
|
let format_error ?(offsets=true) mode (msg, valid_opt, invalid) =
|
||||||
let invalid_lexeme = LexToken.to_lexeme invalid in
|
|
||||||
let invalid_region = LexToken.to_region invalid in
|
let invalid_region = LexToken.to_region invalid in
|
||||||
let header =
|
let header =
|
||||||
"Parse error " ^
|
"Parse error " ^ invalid_region#to_string ~offsets mode in
|
||||||
invalid_region#to_string ~offsets mode in
|
let trailer =
|
||||||
let after =
|
|
||||||
match valid_opt with
|
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 ->
|
| Some valid ->
|
||||||
let valid_lexeme = LexToken.to_lexeme valid
|
let valid_lexeme = LexToken.to_lexeme valid in
|
||||||
in Printf.sprintf ", after \"%s\" and" valid_lexeme in
|
let s = Printf.sprintf ", after \"%s\"" valid_lexeme in
|
||||||
let header = header ^ after in
|
if LexToken.is_eof invalid then s
|
||||||
let before = Printf.sprintf " before \"%s\"" invalid_lexeme in
|
else
|
||||||
let header = header ^ before in
|
let invalid_lexeme = LexToken.to_lexeme invalid in
|
||||||
header ^ (if message = "" then ".\n" else ":\n" ^ message)
|
Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in
|
||||||
|
let header = header ^ trailer in
|
||||||
|
header ^ (if msg = "" then ".\n" else ":\n" ^ msg)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -65,7 +65,7 @@ type t =
|
|||||||
(* Comparisons *)
|
(* Comparisons *)
|
||||||
|
|
||||||
| EQ of Region.t (* "=" *)
|
| EQ of Region.t (* "=" *)
|
||||||
| EQEQ of Region.t (* "=" *)
|
| EQEQ of Region.t (* "==" *)
|
||||||
| NE of Region.t (* "!=" *)
|
| NE of Region.t (* "!=" *)
|
||||||
| LT of Region.t (* "<" *)
|
| LT of Region.t (* "<" *)
|
||||||
| GT of Region.t (* ">" *)
|
| GT of Region.t (* ">" *)
|
||||||
|
@ -59,21 +59,24 @@ module Make (Lexer: Lexer.S with module Token := LexToken)
|
|||||||
|
|
||||||
(* Errors *)
|
(* Errors *)
|
||||||
|
|
||||||
let format_error ?(offsets=true) mode (message, valid_opt, invalid) =
|
let format_error ?(offsets=true) mode (msg, valid_opt, invalid) =
|
||||||
let invalid_lexeme = LexToken.to_lexeme invalid in
|
|
||||||
let invalid_region = LexToken.to_region invalid in
|
let invalid_region = LexToken.to_region invalid in
|
||||||
let header =
|
let header =
|
||||||
"Parse error " ^
|
"Parse error " ^ invalid_region#to_string ~offsets mode in
|
||||||
invalid_region#to_string ~offsets mode in
|
let trailer =
|
||||||
let after =
|
|
||||||
match valid_opt with
|
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 ->
|
| Some valid ->
|
||||||
let valid_lexeme = LexToken.to_lexeme valid
|
let valid_lexeme = LexToken.to_lexeme valid in
|
||||||
in Printf.sprintf ", after \"%s\" and" valid_lexeme in
|
let s = Printf.sprintf ", after \"%s\"" valid_lexeme in
|
||||||
let header = header ^ after in
|
if LexToken.is_eof invalid then s
|
||||||
let before = Printf.sprintf " before \"%s\"" invalid_lexeme in
|
else
|
||||||
let header = header ^ before in
|
let invalid_lexeme = LexToken.to_lexeme invalid in
|
||||||
header ^ (if message = "" then ".\n" else ":\n" ^ message)
|
Printf.sprintf "%s and before \"%s\"" s invalid_lexeme in
|
||||||
|
let header = header ^ trailer in
|
||||||
|
header ^ (if msg = "" then ".\n" else ":\n" ^ msg)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user