Commit 981e2823 authored by POTTIER Francois's avatar POTTIER Francois

Cleanup.

parent 1d345d23
...@@ -17,12 +17,23 @@ module E = ...@@ -17,12 +17,23 @@ module E =
(Parser.MenhirInterpreter) (Parser.MenhirInterpreter)
(CalcErrorReporting) (CalcErrorReporting)
(* Define a printer for explanations. We treat an explanation as if it
were just an item: that is, we ignore the position information that
is provided in the explanation. Indeed, this information is hard to
show in text mode. *)
let print_explanation explanation = let print_explanation explanation =
(* not printing positions in the past, as they are hard to show in a
meaningful way in text mode *)
P.print_item (E.item explanation) P.print_item (E.item explanation)
(* Initialize the lexer, and catch any exception raised by the lexer. *) let print_explanations startp explanations =
Printf.fprintf stderr
"At line %d, column %d: syntax error.\n"
startp.Lexing.pos_lnum
startp.Lexing.pos_cnum;
List.iter print_explanation explanations;
flush stderr
(* The rest of the code is as in the [calc] demo. *)
let process (line : string) = let process (line : string) =
let lexbuf = Lexing.from_string line in let lexbuf = Lexing.from_string line in
...@@ -33,14 +44,7 @@ let process (line : string) = ...@@ -33,14 +44,7 @@ let process (line : string) =
| Lexer.Error msg -> | Lexer.Error msg ->
Printf.fprintf stderr "%s%!" msg Printf.fprintf stderr "%s%!" msg
| E.Error ((startp, _), explanations) -> | E.Error ((startp, _), explanations) ->
Printf.fprintf stderr print_explanations startp explanations
"At line %d, column %d: syntax error.\n"
startp.Lexing.pos_lnum
startp.Lexing.pos_cnum;
List.iter print_explanation explanations;
flush stderr
(* The rest of the code is as in the [calc] demo. *)
let process (optional_line : string option) = let process (optional_line : string option) =
match optional_line with match optional_line with
......
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