summaryrefslogtreecommitdiff
path: root/src/main.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-12-05 18:54:09 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-12-05 18:54:09 +0100
commitbfb562d7c734f76811314773ea248d9f781a2510 (patch)
tree25b821b35136c26078c49cc931bad08c96313f78 /src/main.ml
parentf16b5e2e18e06ec1fb14c7f29a560c3ca596b576 (diff)
parent965574e65f40e58a3a9c5e3bc288ed4124648f2a (diff)
downloadLPC-Projet-bfb562d7c734f76811314773ea248d9f781a2510.tar.gz
LPC-Projet-bfb562d7c734f76811314773ea248d9f781a2510.zip
Merge branch 'master' of github.com:fatlevis/LPC-Projet
Diffstat (limited to 'src/main.ml')
-rw-r--r--src/main.ml25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main.ml b/src/main.ml
index c64381c..9fb4e46 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -3,6 +3,7 @@ open Lexing
let parse_only = ref false
let dump = ref false
+let dumpt = ref false
let ifile = ref ""
@@ -15,17 +16,20 @@ let localisation pos =
let c = pos.pos_cnum - pos.pos_bol + 1 in
eprintf "File \"%s\", line %d, characters %d-%d:\n"
!ifile l (c-1) c
+
+let localisation2 (pos1,pos2) =
+ let l = pos1.pos_lnum in
+ let c1 = pos1.pos_cnum - pos1.pos_bol + 1 in
+ let c2 = pos2.pos_cnum - pos2.pos_bol + 1 in
+ eprintf "File \"%s\", line %d, characters %d-%d:\n"
+ !ifile l c1 c2
let options = [
"--parse-only", Arg.Set parse_only, "Stops after parsing of the input file.";
- "--dump", Arg.Set dump, "Dump the AST after parsing."
+ "--dump", Arg.Set dump, "Dump the AST after parsing.";
+ "--dumpt", Arg.Set dumpt, "Dump the AST after typing."
]
-let localisation pos =
- let l = pos.pos_lnum in
- let c = pos.pos_cnum - pos.pos_bol + 1 in
- eprintf "File \"%s\", line %d, characters %d-%d:\n" !ifile l (c-1) c
-
let () =
Arg.parse options (set_var ifile) usage;
@@ -43,18 +47,25 @@ let () =
try
let p = Parser.prog Lexer.token buf in
+ let t = Typing.prog p in
close_in f;
if !dump then Pretty.print_prog p;
+ if !dumpt then Pretty_typing.print_prog t;
with
| Lexer.Lexing_error s ->
localisation (Lexing.lexeme_start_p buf);
eprintf "Lexical analysis error: %s@." s;
exit 1
| Parser.Error ->
- localisation (Lexing.lexeme_start_p buf);
+ localisation (Lexing.lexeme_start_p buf);
eprintf "Parsing error.@.";
exit 1
+ | Typing.Error (loc, msg) ->
+ localisation2 loc;
+ eprintf "%s" msg;
+ exit 1
+
| _ ->
eprintf "Unexpected error...@.";
exit 2