Commit 1a570d12 authored by POTTIER Francois's avatar POTTIER Francois

Cleanup: modified [Error.errorp] to take a format.

parent abb1f3ad
......@@ -84,10 +84,6 @@ let printN positions message = (* TEMPORARY *)
let error_message message =
"Error: " ^ message
let old_error positions message = (* TEMPORARY *)
printN positions (error_message message);
exit 1
let error positions format =
print_positions positions;
Printf.kfprintf
......@@ -95,8 +91,8 @@ let error positions format =
stderr
("Error: " ^^ format ^^ "\n%!")
let errorp v message =
old_error [ Positions.position v ] message
let errorp v =
error [ Positions.position v ]
let signal positions message =
printN positions message;
......
......@@ -41,7 +41,7 @@ val error: Positions.positions -> ('a, out_channel, unit, 'b) format4 -> 'a
(* [errorp v msg] displays the error message [msg], referring to the
position range carried by [v], and exits. *)
val errorp: 'a Positions.located -> string -> 'b
val errorp: _ Positions.located -> ('a, out_channel, unit, 'b) format4 -> 'a
(* [warning ps msg] displays the warning message [msg], referring to
the positions [ps]. *)
......
......@@ -337,9 +337,7 @@ rule main = parse
{ PLUS }
| (lowercase identchar *) as id
{ if Hashtbl.mem reserved id then
Error.errorp
(Positions.with_poss (lexeme_start_p lexbuf) (lexeme_end_p lexbuf) ())
"this is an Objective Caml reserved word."
error2 lexbuf "this is an Objective Caml reserved word."
else
LID (with_pos (cpos lexbuf) id)
}
......
......@@ -595,7 +595,7 @@ let expand p_grammar =
let accu = types_from_list q in
let mangled = mangle nt in
if StringMap.mem mangled accu then
Error.error [Positions.position (Parameters.with_pos nt)]
Error.error [Parameters.position nt]
"there are multiple %%type declarations for nonterminal %s."
mangled;
StringMap.add mangled (Positions.value ty) accu
......@@ -610,7 +610,7 @@ let expand p_grammar =
let accu = on_error_reduce_from_list ps in
let mangled = mangle nt in
if StringSet.mem mangled accu then
Error.error [Positions.position (Parameters.with_pos nt)]
Error.error [Parameters.position nt]
"there are multiple %%on_error_reduce declarations for nonterminal %s."
mangled;
StringSet.add mangled accu
......
......@@ -43,7 +43,7 @@ let join_declaration filename (grammar : grammar) decl =
if token_property.tk_is_declared then
Error.errorp decl
(Printf.sprintf "the token %s has multiple definitions." terminal)
"the token %s has multiple definitions." terminal
(* Otherwise, update the previous definition. *)
......@@ -594,7 +594,7 @@ let check_keywords producers action =
) producers;
if not !found then
Error.errorp keyword
(Printf.sprintf "%s refers to a nonexistent symbol." id)
"%s refers to a nonexistent symbol." id
| Position (Left, _, _)
| SyntaxError ->
()
......@@ -627,10 +627,9 @@ let check_parameterized_grammar_is_well_defined grammar =
List.iter (fun p ->
let head_symb = parameter_head_symb p in
if not (StringMap.mem (value head_symb) grammar.p_rules) then
Error.errorp (Parameters.with_pos p)
(Printf.sprintf
Error.error [Parameters.position p]
"this should be a nonterminal symbol.\n\
%s declarations are applicable only to nonterminal symbols." kind)
%s declarations are applicable only to nonterminal symbols." kind
) ps
in
check "%type" (List.map fst grammar.p_types);
......@@ -687,7 +686,7 @@ let check_parameterized_grammar_is_well_defined grammar =
if not ((StringMap.find s grammar.p_tokens).tk_is_declared
|| List.mem s reserved) then
Error.errorp symbol
(Printf.sprintf "%s has not been declared as a token." s)
"%s has not been declared as a token." s
with Not_found -> ());
already_seen
......@@ -706,13 +705,13 @@ let check_parameterized_grammar_is_well_defined grammar =
(* It is forbidden to use the %prec directive with %inline. *)
if prule.pr_inline_flag then
Error.errorp terminal
"use of %prec is forbidden in an %inlined nonterminal definition.";
"use of %%prec is forbidden in an %%inlined nonterminal definition.";
(* Furthermore, the symbol following %prec must be a valid
token identifier. *)
if not (StringMap.mem terminal.value grammar.p_tokens) then
Error.errorp terminal
(Printf.sprintf "%s is undefined." terminal.value))
"%s is undefined." terminal.value)
prule.pr_branches;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment