Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
POTTIER Francois
menhir
Commits
a991d7cb
Commit
a991d7cb
authored
Oct 16, 2015
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplification of [FancyDriver] using [loop_handle].
parent
535cee59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
25 deletions
+9
-25
src/fancyDriver.ml
src/fancyDriver.ml
+9
-25
No files found.
src/fancyDriver.ml
View file @
a991d7cb
...
...
@@ -5,30 +5,13 @@
in a more ambitious manner, so as to help our end users understand
their mistakes. *)
(* TEMPORARY a lot of code is copied from [Engine]. Can we avoid it? *)
open
MenhirLib
.
General
(* streams: Nil, Cons *)
open
Parser
.
MenhirInterpreter
(* incremental API to our parser *)
(* The loop which drives the parser. At each iteration, we analyze a
checkpoint produced by the parser, and act in an appropriate manner.
We have to do this in order to get ahold of the current state when
a syntax error is encountered. *)
(* [fail] is invoked if a syntax error is encountered. *)
let
rec
loop
lexer
lexbuf
(
checkpoint
:
'
a
checkpoint
)
:
'
a
=
let
open
Lexing
in
let
fail
lexbuf
checkpoint
=
match
checkpoint
with
|
InputNeeded
_
->
(* The parser needs a token. Request one from the lexer,
and offer it to the parser, which will produce a new
checkpoint. Then, repeat. *)
let
token
=
lexer
lexbuf
in
let
checkpoint
=
offer
checkpoint
(
token
,
lexbuf
.
lex_start_p
,
lexbuf
.
lex_curr_p
)
in
loop
lexer
lexbuf
checkpoint
|
Shifting
_
|
AboutToReduce
_
->
let
checkpoint
=
resume
checkpoint
in
loop
lexer
lexbuf
checkpoint
|
HandlingError
env
->
(* The parser has suspended itself because of a syntax error. Stop.
Find out which state the parser is currently in. *)
...
...
@@ -59,15 +42,16 @@ let rec loop lexer lexbuf (checkpoint : 'a checkpoint) : 'a =
let
message
=
String
.
sub
message
0
(
String
.
length
message
-
1
)
in
(* Display our message and die. *)
Error
.
error
(
Positions
.
lexbuf
lexbuf
)
message
|
Accepted
v
->
v
|
Rejected
->
(* The parser rejects this input. This cannot happen because
we stop as soon as the parser reports [HandlingError]. *)
|
_
->
(* This cannot happen. *)
assert
false
(* The entry point. *)
let
grammar
lexer
lexbuf
=
loop
lexer
lexbuf
(
Parser
.
Incremental
.
grammar
()
)
loop_handle
(
fun
v
->
v
)
(
fail
lexbuf
)
(
lexer_lexbuf_to_supplier
lexer
lexbuf
)
(
Parser
.
Incremental
.
grammar
()
)
Write
Preview
Markdown
is supported
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