Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
POTTIER Francois
menhir
Commits
981e2823
Commit
981e2823
authored
Aug 29, 2015
by
POTTIER Francois
Browse files
Cleanup.
parent
1d345d23
Changes
1
Hide whitespace changes
Inline
Side-by-side
demos/calc-inspection/calc.ml
View file @
981e2823
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment