Commit 73d7abcc authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Changed [Makefile] and [FancyDriver] to use --table mode and the incremental API.

parent 6e48be5f
......@@ -63,7 +63,7 @@ stage1:
# descends into another directory when executing commands.
SRC := $(shell pwd)
FLAGS := -v -lg 1 -la 1 -lc 1 --comment --infer --stdlib $(SRC) --strict --fixed-exception
FLAGS := -v -lg 1 -la 1 -lc 1 --table --infer --stdlib $(SRC) --strict --fixed-exception
@$(OCAMLBUILD) -build-dir _stage2 -tag fancy_parser \
......@@ -5,11 +5,51 @@
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? *)
(* A short name for the incremental parser API. *)
module I =
(* The loop which drives the parser. At each iteration, we analyze a
result produced by the parser, and act in an appropriate manner. *)
(* [lexbuf] is the lexing buffer. [result] is the last result produced
by the parser. *)
let rec loop lexer lexbuf (result : 'a I.result) : 'a =
let open Lexing in
match result with
| I.InputNeeded _ ->
(* The parser needs a token. Request one from the lexer,
and offer it to the parser, which will produce a new
result. Then, repeat. *)
let token = lexer lexbuf in
let result = I.offer result (token, lexbuf.lex_start_p, lexbuf.lex_curr_p) in
loop lexer lexbuf result
| I.Shifting _
| I.AboutToReduce _ ->
let result = I.resume result in
loop lexer lexbuf result
| I.HandlingError _env ->
(* The parser has suspended itself because of a syntax error. Stop. *)
Printf.fprintf stderr
"At offset %d: syntax error.\n%!"
(lexeme_start lexbuf);
exit 1
| I.Accepted v ->
| I.Rejected ->
(* The parser rejects this input. This cannot happen because
we stop as soon as the parser reports [HandlingError]. *)
assert false
(* The entry point. *)
module F = FancyParserMessages (* TEMPORARY *)
let grammar lexer lexbuf =
Parser.grammar lexer lexbuf
with Parsing.Parse_error ->
Error.error (Positions.lexbuf lexbuf) "Syntax error."
loop lexer lexbuf (Parser.Incremental.grammar())
Supports Markdown
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