Просмотр исходного кода

Shifted error position for syntax errors 1 position to the left

Taddeus Kroes 12 лет назад
Родитель
Сommit
939f21c1b4
1 измененных файлов с 4 добавлено и 2 удалено
  1. 4 2
      phases/parse.ml

+ 4 - 2
phases/parse.ml

@@ -7,12 +7,14 @@ let get_loc lexbuf =
 let shift_loc (fname, ystart, yend, xstart, xend) yshift xshift =
 let shift_loc (fname, ystart, yend, xstart, xend) yshift xshift =
     (fname, ystart + yshift, yend + yshift, xstart + xshift, xend + xshift)
     (fname, ystart + yshift, yend + yshift, xstart + xshift, xend + xshift)
 
 
+let shift_back lexbuf = shift_loc (get_loc lexbuf) 0 (-1)
+
 let parse_with_error lexbuf =
 let parse_with_error lexbuf =
     try Some (Parser.program Lexer.token lexbuf) with
     try Some (Parser.program Lexer.token lexbuf) with
     | Lexer.SyntaxError msg ->
     | Lexer.SyntaxError msg ->
-        raise (LocError (shift_loc (get_loc lexbuf) 0 (-1), msg))
+        raise (LocError ((shift_back lexbuf), msg))
     | Parser.Error ->
     | Parser.Error ->
-        raise (LocError (get_loc lexbuf, "syntax error"))
+        raise (LocError ((shift_back lexbuf), "syntax error"))
 
 
 let phase input =
 let phase input =
     prerr_endline "- Parse input";
     prerr_endline "- Parse input";