| Attached Files | lexing_error_pos_3.11.diff [^] (10,018 bytes) 2011-01-27 16:24 [Show Content] [Hide Content]diff --git ocamlbuild/configuration.ml ocamlbuild/configuration.ml
index c4903ca..8fe791e 100644
--- ocamlbuild/configuration.ml
+++ ocamlbuild/configuration.ml
@@ -25,14 +25,16 @@ let (configs, add_config) =
(fun () -> !configs),
(fun config -> configs := config :: !configs; Hashtbl.clear cache)
-let parse_string s =
- let conf = Lexers.conf_lines None 1 (Printf.sprintf "string: %S" s) (Lexing.from_string s) in
+let parse_lexbuf ?dir source lexbuf =
+ lexbuf.Lexing.lex_curr_p <- { lexbuf.Lexing.lex_curr_p with Lexing.pos_fname = source };
+ let conf = Lexers.conf_lines dir lexbuf in
add_config conf
+let parse_string s = parse_lexbuf (Printf.sprintf "String %S" s) (Lexing.from_string s)
+
let parse_file ?dir file =
with_input_file file begin fun ic ->
- let conf = Lexers.conf_lines dir 1 (Printf.sprintf "file: %S" file) (Lexing.from_channel ic) in
- add_config conf
+ parse_lexbuf ?dir (Printf.sprintf "File %S" file) (Lexing.from_channel ic)
end
let key_match = Glob.eval
diff --git ocamlbuild/lexers.mli ocamlbuild/lexers.mli
index 472a3ca..9296eb5 100644
--- ocamlbuild/lexers.mli
+++ ocamlbuild/lexers.mli
@@ -11,7 +11,7 @@
(* Original author: Nicolas Pouillard *)
-exception Error of string
+exception Error of (string * Lexing.position)
type conf_values =
{ plus_tags : string list;
@@ -32,7 +32,7 @@ val comma_or_blank_sep_strings : Lexing.lexbuf -> string list
Example: "aaa:bbb:::ccc" -> ["aaa"; "bbb"; "ccc"] *)
val colon_sep_strings : Lexing.lexbuf -> string list
-val conf_lines : string option -> int -> string -> Lexing.lexbuf -> conf
+val conf_lines : string option -> Lexing.lexbuf -> conf
val path_scheme : bool -> Lexing.lexbuf ->
[ `Word of string
| `Var of (string * Glob.globber)
diff --git ocamlbuild/lexers.mll ocamlbuild/lexers.mll
index 67fa1e6..b15386f 100644
--- ocamlbuild/lexers.mll
+++ ocamlbuild/lexers.mll
@@ -12,7 +12,10 @@
(* Original author: Nicolas Pouillard *)
{
-exception Error of string
+exception Error of (string * Lexing.position)
+
+let error lexbuf fmt = Printf.ksprintf (fun s -> raise (Error (s,Lexing.lexeme_start_p lexbuf))) fmt
+
open Glob_ast
type conf_values =
@@ -45,81 +48,85 @@ let pattern = ([^ '(' ')' '\\' ] | '\\' [ '(' ')' ])*
rule ocamldep_output = parse
| ([^ ':' '\n' '\r' ]+ as k) ':' { let x = (k, space_sep_strings_nl lexbuf) in x :: ocamldep_output lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon followed by space-separated module name list") }
+ | _ { error lexbuf "Expecting colon followed by space-separated module name list" }
and space_sep_strings_nl = parse
| space* (not_blank+ as word) { word :: space_sep_strings_nl lexbuf }
- | space* newline { [] }
- | _ { raise (Error "Expecting space-separated strings terminated with newline") }
+ | space* newline { Lexing.new_line lexbuf; [] }
+ | _ { error lexbuf "Expecting space-separated strings terminated with newline" }
and space_sep_strings = parse
| space* (not_blank+ as word) { word :: space_sep_strings lexbuf }
| space* newline? eof { [] }
- | _ { raise (Error "Expecting space-separated strings") }
+ | _ { error lexbuf "Expecting space-separated strings" }
and blank_sep_strings = parse
| blank* '#' not_newline* newline { blank_sep_strings lexbuf }
| blank* '#' not_newline* eof { [] }
| blank* (not_blank+ as word) { word :: blank_sep_strings lexbuf }
| blank* eof { [] }
- | _ { raise (Error "Expecting blank-separated strings") }
+ | _ { error lexbuf "Expecting blank-separated strings" }
and comma_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (1)") }
+ | _ { error lexbuf "Expecting comma-separated strings (1)" }
and comma_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (2)") }
+ | _ { error lexbuf "Expecting comma-separated strings (2)" }
and comma_or_blank_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (1)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (1)" }
and comma_or_blank_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (2)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (2)" }
and colon_sep_strings = parse
| ([^ ':']+ as word) eof { [word] }
| ([^ ':']+ as word) { word :: colon_sep_strings_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon-separated strings (1)") }
+ | _ { error lexbuf "Expecting colon-separated strings (1)" }
and colon_sep_strings_aux = parse
| ':'+ ([^ ':']+ as word) { word :: colon_sep_strings_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon-separated strings (2)") }
+ | _ { error lexbuf "Expecting colon-separated strings (2)" }
-and conf_lines dir pos err = parse
- | space* '#' not_newline* newline { conf_lines dir (pos + 1) err lexbuf }
+and conf_lines dir = parse
+ | space* '#' not_newline* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* '#' not_newline* eof { [] }
- | space* newline { conf_lines dir (pos + 1) err lexbuf }
+ | space* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* eof { [] }
| space* (not_newline_nor_colon+ as k) space* ':' space*
{
- let bexpr = Glob.parse ?dir k in
- let v1 = conf_value pos err empty lexbuf in
- let v2 = conf_values pos err v1 lexbuf in
- let rest = conf_lines dir (pos + 1) err lexbuf in (bexpr, v2) :: rest
+ let bexpr =
+ try Glob.parse ?dir k
+ with exn -> error lexbuf "Bad key %S : %s" k (Printexc.to_string exn)
+ in
+ let v1 = conf_value empty lexbuf in
+ let v2 = conf_values v1 lexbuf in
+ Lexing.new_line lexbuf; (* FIXME values may have escaped newlines *)
+ let rest = conf_lines dir lexbuf in (bexpr,v2) :: rest
}
- | _ { raise (Error(Printf.sprintf "Bad key in configuration line at line %d (from %s)" pos err)) }
+ | _ { error lexbuf "Bad key" }
-and conf_value pos err x = parse
+and conf_value x = parse
| '-' (flag_name as t1) '(' (flag_value as t2) ')' { { (x) with minus_flags = (t1, t2) :: x.minus_flags } }
| '+'? (flag_name as t1) '(' (flag_value as t2) ')' { { (x) with plus_flags = (t1, t2) :: x.plus_flags } }
| '-' (tag as tag) { { (x) with minus_tags = tag :: x.minus_tags } }
| '+'? (tag as tag) { { (x) with plus_tags = tag :: x.plus_tags } }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad value in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad value" }
-and conf_values pos err x = parse
- | space_or_esc_nl* ',' space_or_esc_nl* { conf_values pos err (conf_value pos err x lexbuf) lexbuf }
+and conf_values x = parse
+ | space_or_esc_nl* ',' space_or_esc_nl* { conf_values (conf_value x lexbuf) lexbuf }
| (newline | eof) { x }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad values in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad values" }
and path_scheme patt_allowed = parse
| ([^ '%' ]+ as prefix)
@@ -130,14 +137,13 @@ and path_scheme patt_allowed = parse
{ if patt_allowed then
let patt = My_std.String.implode (unescape (Lexing.from_string patt)) in
`Var (var, Glob.parse patt) :: path_scheme patt_allowed lexbuf
- else raise (Error(
- Printf.sprintf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)"
- var patt)) }
+ else
+ error lexbuf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)" var patt }
| '%'
{ `Var ("", Bool.True) :: path_scheme patt_allowed lexbuf }
| eof
{ [] }
- | _ { raise (Error("Bad pathanme scheme")) }
+ | _ { error lexbuf "Bad pathanme scheme" }
and unescape = parse
| '\\' (['(' ')'] as c) { c :: unescape lexbuf }
diff --git ocamlbuild/main.ml ocamlbuild/main.ml
index 7b48b42..3699577 100644
--- ocamlbuild/main.ml
+++ ocamlbuild/main.ml
@@ -264,8 +264,10 @@ let main () =
| Ocaml_utils.Ocamldep_error msg ->
Log.eprintf "Ocamldep error: %s" msg;
exit rc_ocamldep_error
- | Lexers.Error msg ->
- Log.eprintf "Lexical analysis error: %s" msg;
+ | Lexers.Error (msg,pos) ->
+ let module L = Lexing in
+ Log.eprintf "%s, line %d, column %d:" pos.L.pos_fname pos.L.pos_lnum (pos.L.pos_cnum - pos.L.pos_bol);
+ Log.eprintf "Lexing error: %s" msg;
exit rc_lexing_error
| Arg.Bad msg ->
Log.eprintf "%s" msg;
diff --git ocamlbuild/ocaml_utils.ml ocamlbuild/ocaml_utils.ml
index bbfe60e..a4741a8 100644
--- ocamlbuild/ocaml_utils.ml
+++ ocamlbuild/ocaml_utils.ml
@@ -140,7 +140,7 @@ let read_path_dependencies =
with_input_file depends begin fun ic ->
let ocamldep_output =
try Lexers.ocamldep_output (Lexing.from_channel ic)
- with Lexers.Error msg -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
+ with Lexers.Error (msg,_) -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
let deps =
List.fold_right begin fun (path, deps) acc ->
let module_name' = module_name_of_pathname path in
lexing_error_pos_3.12.diff [^] (11,326 bytes) 2011-01-27 16:25 [Show Content] [Hide Content]diff --git ocamlbuild/command.ml ocamlbuild/command.ml
index 131cd85..63f89e8 100644
--- ocamlbuild/command.ml
+++ ocamlbuild/command.ml
@@ -94,7 +94,7 @@ let env_path = lazy begin
let paths =
try
Lexers.parse_environment_path (Lexing.from_string path_var)
- with Lexers.Error msg -> raise (Lexers.Error ("$PATH: " ^ msg))
+ with Lexers.Error (msg,pos) -> raise (Lexers.Error ("$PATH: " ^ msg, pos))
in
let norm_current_dir_name path =
if path = "" then Filename.current_dir_name else path
diff --git ocamlbuild/configuration.ml ocamlbuild/configuration.ml
index 7a4f2f4..a36fb73 100644
--- ocamlbuild/configuration.ml
+++ ocamlbuild/configuration.ml
@@ -31,17 +31,17 @@ let (configs, add_config) =
configs := config :: !configs;
Hashtbl.clear cache)
-let parse_string s =
- let conf = Lexers.conf_lines None 1 (Printf.sprintf "string: %S" s) (Lexing.from_string s) in
+let parse_lexbuf ?dir source lexbuf =
+ lexbuf.Lexing.lex_curr_p <- { lexbuf.Lexing.lex_curr_p with Lexing.pos_fname = source };
+ let conf = Lexers.conf_lines dir lexbuf in
add_config conf
+let parse_string s = parse_lexbuf (Printf.sprintf "String %S" s) (Lexing.from_string s)
+
let parse_file ?dir file =
- try
- with_input_file file begin fun ic ->
- let conf = Lexers.conf_lines dir 1 (Printf.sprintf "file: %S" file) (Lexing.from_channel ic) in
- add_config conf
- end
- with Lexers.Error msg -> raise (Lexers.Error (file ^ ": " ^ msg))
+ with_input_file file begin fun ic ->
+ parse_lexbuf ?dir (Printf.sprintf "File %S" file) (Lexing.from_channel ic)
+ end
let key_match = Glob.eval
diff --git ocamlbuild/findlib.ml ocamlbuild/findlib.ml
index 873adba..f83ea56 100644
--- ocamlbuild/findlib.ml
+++ ocamlbuild/findlib.ml
@@ -109,7 +109,7 @@ let rec query name =
(* TODO: Improve to differenciate whether ocamlfind cannot be
run or is not installed *)
error Cannot_run_ocamlfind
- | Lexers.Error s ->
+ | Lexers.Error (s,_) ->
error (Cannot_parse_query (name, s))
let list () =
diff --git ocamlbuild/lexers.mli ocamlbuild/lexers.mli
index 2f37edc..9f17946 100644
--- ocamlbuild/lexers.mli
+++ ocamlbuild/lexers.mli
@@ -11,7 +11,7 @@
(* Original author: Nicolas Pouillard *)
-exception Error of string
+exception Error of (string * Lexing.position)
type conf_values =
{ plus_tags : string list;
@@ -33,7 +33,7 @@ val trim_blanks : Lexing.lexbuf -> string
":aaa:bbb:::ccc:" -> [""; "aaa"; "bbb"; ""; ""; "ccc"; ""] *)
val parse_environment_path : Lexing.lexbuf -> string list
-val conf_lines : string option -> int -> string -> Lexing.lexbuf -> conf
+val conf_lines : string option -> Lexing.lexbuf -> conf
val path_scheme : bool -> Lexing.lexbuf ->
[ `Word of string
| `Var of (string * Glob.globber)
diff --git ocamlbuild/lexers.mll ocamlbuild/lexers.mll
index 7b191b0..6635975 100644
--- ocamlbuild/lexers.mll
+++ ocamlbuild/lexers.mll
@@ -12,7 +12,10 @@
(* Original author: Nicolas Pouillard *)
{
-exception Error of string
+exception Error of (string * Lexing.position)
+
+let error lexbuf fmt = Printf.ksprintf (fun s -> raise (Error (s,Lexing.lexeme_start_p lexbuf))) fmt
+
open Glob_ast
type conf_values =
@@ -41,45 +44,45 @@ let pattern = ([^ '(' ')' '\\' ] | '\\' [ '(' ')' ])*
rule ocamldep_output = parse
| ([^ ':' '\n' '\r' ]+ as k) ':' { let x = (k, space_sep_strings_nl lexbuf) in x :: ocamldep_output lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon followed by space-separated module name list") }
+ | _ { error lexbuf "Expecting colon followed by space-separated module name list" }
and space_sep_strings_nl = parse
| space* (not_blank+ as word) { word :: space_sep_strings_nl lexbuf }
- | space* newline { [] }
- | _ { raise (Error "Expecting space-separated strings terminated with newline") }
+ | space* newline { Lexing.new_line lexbuf; [] }
+ | _ { error lexbuf "Expecting space-separated strings terminated with newline" }
and space_sep_strings = parse
| space* (not_blank+ as word) { word :: space_sep_strings lexbuf }
| space* newline? eof { [] }
- | _ { raise (Error "Expecting space-separated strings") }
+ | _ { error lexbuf "Expecting space-separated strings" }
and blank_sep_strings = parse
| blank* '#' not_newline* newline { blank_sep_strings lexbuf }
| blank* '#' not_newline* eof { [] }
| blank* (not_blank+ as word) { word :: blank_sep_strings lexbuf }
| blank* eof { [] }
- | _ { raise (Error "Expecting blank-separated strings") }
+ | _ { error lexbuf "Expecting blank-separated strings" }
and comma_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (1)") }
+ | _ { error lexbuf "Expecting comma-separated strings (1)" }
and comma_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (2)") }
+ | _ { error lexbuf "Expecting comma-separated strings (2)" }
and comma_or_blank_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (1)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (1)" }
and comma_or_blank_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (2)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (2)" }
and parse_environment_path = parse
| ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
@@ -88,31 +91,35 @@ and parse_environment_path = parse
and parse_environment_path_aux = parse
| ':' ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Impossible: expecting colon-separated strings") }
+ | _ { error lexbuf "Impossible: expecting colon-separated strings" }
-and conf_lines dir pos err = parse
- | space* '#' not_newline* newline { conf_lines dir (pos + 1) err lexbuf }
+and conf_lines dir = parse
+ | space* '#' not_newline* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* '#' not_newline* eof { [] }
- | space* newline { conf_lines dir (pos + 1) err lexbuf }
+ | space* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* eof { [] }
| space* (not_newline_nor_colon+ as k) space* ':' space*
{
- let bexpr = Glob.parse ?dir k in
- let v1 = conf_value pos err empty lexbuf in
- let v2 = conf_values pos err v1 lexbuf in
- let rest = conf_lines dir (pos + 1) err lexbuf in (bexpr, v2) :: rest
+ let bexpr =
+ try Glob.parse ?dir k
+ with exn -> error lexbuf "Bad key %S : %s" k (Printexc.to_string exn)
+ in
+ let v1 = conf_value empty lexbuf in
+ let v2 = conf_values v1 lexbuf in
+ Lexing.new_line lexbuf; (* FIXME values may have escaped newlines *)
+ let rest = conf_lines dir lexbuf in (bexpr,v2) :: rest
}
- | _ { raise (Error(Printf.sprintf "Bad key in configuration line at line %d (from %s)" pos err)) }
+ | _ { error lexbuf "Bad key" }
-and conf_value pos err x = parse
+and conf_value x = parse
| '-' (tag as tag) { { (x) with minus_tags = tag :: x.minus_tags } }
| '+'? (tag as tag) { { (x) with plus_tags = tag :: x.plus_tags } }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad value in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad value" }
-and conf_values pos err x = parse
- | space_or_esc_nl* ',' space_or_esc_nl* { conf_values pos err (conf_value pos err x lexbuf) lexbuf }
+and conf_values x = parse
+ | space_or_esc_nl* ',' space_or_esc_nl* { conf_values (conf_value x lexbuf) lexbuf }
| (newline | eof) { x }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad values in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad values" }
and path_scheme patt_allowed = parse
| ([^ '%' ]+ as prefix)
@@ -123,14 +130,13 @@ and path_scheme patt_allowed = parse
{ if patt_allowed then
let patt = My_std.String.implode (unescape (Lexing.from_string patt)) in
`Var (var, Glob.parse patt) :: path_scheme patt_allowed lexbuf
- else raise (Error(
- Printf.sprintf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)"
- var patt)) }
+ else
+ error lexbuf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)" var patt }
| '%'
{ `Var ("", Bool.True) :: path_scheme patt_allowed lexbuf }
| eof
{ [] }
- | _ { raise (Error("Bad pathanme scheme")) }
+ | _ { error lexbuf "Bad pathanme scheme" }
and unescape = parse
| '\\' (['(' ')'] as c) { c :: unescape lexbuf }
@@ -146,11 +152,11 @@ and ocamlfind_query = parse
"linkopts:" space* (not_newline* as lo) newline+
"location:" space* (not_newline* as l) newline+
{ n, d, v, a, lo, l }
- | _ { raise (Error "Bad ocamlfind query") }
+ | _ { error lexbuf "Bad ocamlfind query" }
and trim_blanks = parse
| blank* (not_blank* as word) blank* { word }
- | _ { raise (Error "Bad input for trim_blanks") }
+ | _ { error lexbuf "Bad input for trim_blanks" }
and tag_gen = parse
| (normal+ as name) ('(' ([^')']* as param) ')')? { name, param }
diff --git ocamlbuild/main.ml ocamlbuild/main.ml
index 668fd81..25ad0bd 100644
--- ocamlbuild/main.ml
+++ ocamlbuild/main.ml
@@ -271,8 +271,10 @@ let main () =
| Ocaml_utils.Ocamldep_error msg ->
Log.eprintf "Ocamldep error: %s" msg;
exit rc_ocamldep_error
- | Lexers.Error msg ->
- Log.eprintf "Lexical analysis error: %s" msg;
+ | Lexers.Error (msg,pos) ->
+ let module L = Lexing in
+ Log.eprintf "%s, line %d, column %d:" pos.L.pos_fname pos.L.pos_lnum (pos.L.pos_cnum - pos.L.pos_bol);
+ Log.eprintf "Lexing error: %s" msg;
exit rc_lexing_error
| Arg.Bad msg ->
Log.eprintf "%s" msg;
diff --git ocamlbuild/ocaml_utils.ml ocamlbuild/ocaml_utils.ml
index 3dafe25..64fd654 100644
--- ocamlbuild/ocaml_utils.ml
+++ ocamlbuild/ocaml_utils.ml
@@ -145,7 +145,7 @@ let read_path_dependencies =
with_input_file depends begin fun ic ->
let ocamldep_output =
try Lexers.ocamldep_output (Lexing.from_channel ic)
- with Lexers.Error msg -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
+ with Lexers.Error (msg,_) -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
let deps =
List.fold_right begin fun (path, deps) acc ->
let module_name' = module_name_of_pathname path in
lexing_error_pos_4.00_svn.diff [^] (11,812 bytes) 2012-07-09 11:39 [Show Content] [Hide Content]diff --git a/ocamlbuild/command.ml b/ocamlbuild/command.ml
index 1ce80c9..2120a2a 100644
--- a/ocamlbuild/command.ml
+++ b/ocamlbuild/command.ml
@@ -100,7 +100,7 @@ let env_path = lazy begin
let paths =
try
parse_path (Lexing.from_string path_var)
- with Lexers.Error msg -> raise (Lexers.Error ("$PATH: " ^ msg))
+ with Lexers.Error (msg,pos) -> raise (Lexers.Error ("$PATH: " ^ msg, pos))
in
let norm_current_dir_name path =
if path = "" then Filename.current_dir_name else path
diff --git a/ocamlbuild/configuration.ml b/ocamlbuild/configuration.ml
index 7a4f2f4..a36fb73 100644
--- a/ocamlbuild/configuration.ml
+++ b/ocamlbuild/configuration.ml
@@ -31,17 +31,17 @@ let (configs, add_config) =
configs := config :: !configs;
Hashtbl.clear cache)
-let parse_string s =
- let conf = Lexers.conf_lines None 1 (Printf.sprintf "string: %S" s) (Lexing.from_string s) in
+let parse_lexbuf ?dir source lexbuf =
+ lexbuf.Lexing.lex_curr_p <- { lexbuf.Lexing.lex_curr_p with Lexing.pos_fname = source };
+ let conf = Lexers.conf_lines dir lexbuf in
add_config conf
+let parse_string s = parse_lexbuf (Printf.sprintf "String %S" s) (Lexing.from_string s)
+
let parse_file ?dir file =
- try
- with_input_file file begin fun ic ->
- let conf = Lexers.conf_lines dir 1 (Printf.sprintf "file: %S" file) (Lexing.from_channel ic) in
- add_config conf
- end
- with Lexers.Error msg -> raise (Lexers.Error (file ^ ": " ^ msg))
+ with_input_file file begin fun ic ->
+ parse_lexbuf ?dir (Printf.sprintf "File %S" file) (Lexing.from_channel ic)
+ end
let key_match = Glob.eval
diff --git a/ocamlbuild/findlib.ml b/ocamlbuild/findlib.ml
index 873adba..f83ea56 100644
--- a/ocamlbuild/findlib.ml
+++ b/ocamlbuild/findlib.ml
@@ -109,7 +109,7 @@ let rec query name =
(* TODO: Improve to differenciate whether ocamlfind cannot be
run or is not installed *)
error Cannot_run_ocamlfind
- | Lexers.Error s ->
+ | Lexers.Error (s,_) ->
error (Cannot_parse_query (name, s))
let list () =
diff --git a/ocamlbuild/lexers.mli b/ocamlbuild/lexers.mli
index bc5de4c..4d6e2ec 100644
--- a/ocamlbuild/lexers.mli
+++ b/ocamlbuild/lexers.mli
@@ -11,7 +11,7 @@
(* Original author: Nicolas Pouillard *)
-exception Error of string
+exception Error of (string * Lexing.position)
type conf_values =
{ plus_tags : string list;
@@ -35,7 +35,7 @@ val parse_environment_path : Lexing.lexbuf -> string list
(* Same one, for Windows (PATH is ;-separated) *)
val parse_environment_path_w : Lexing.lexbuf -> string list
-val conf_lines : string option -> int -> string -> Lexing.lexbuf -> conf
+val conf_lines : string option -> Lexing.lexbuf -> conf
val path_scheme : bool -> Lexing.lexbuf ->
[ `Word of string
| `Var of (string * Glob.globber)
diff --git a/ocamlbuild/lexers.mll b/ocamlbuild/lexers.mll
index 2206f86..18965fd 100644
--- a/ocamlbuild/lexers.mll
+++ b/ocamlbuild/lexers.mll
@@ -12,7 +12,10 @@
(* Original author: Nicolas Pouillard *)
{
-exception Error of string
+exception Error of (string * Lexing.position)
+
+let error lexbuf fmt = Printf.ksprintf (fun s -> raise (Error (s,Lexing.lexeme_start_p lexbuf))) fmt
+
open Glob_ast
type conf_values =
@@ -41,45 +44,45 @@ let pattern = ([^ '(' ')' '\\' ] | '\\' [ '(' ')' ])*
rule ocamldep_output = parse
| ([^ ':' '\n' '\r' ]+ as k) ':' { let x = (k, space_sep_strings_nl lexbuf) in x :: ocamldep_output lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon followed by space-separated module name list") }
+ | _ { error lexbuf "Expecting colon followed by space-separated module name list" }
and space_sep_strings_nl = parse
| space* (not_blank+ as word) { word :: space_sep_strings_nl lexbuf }
- | space* newline { [] }
- | _ { raise (Error "Expecting space-separated strings terminated with newline") }
+ | space* newline { Lexing.new_line lexbuf; [] }
+ | _ { error lexbuf "Expecting space-separated strings terminated with newline" }
and space_sep_strings = parse
| space* (not_blank+ as word) { word :: space_sep_strings lexbuf }
| space* newline? eof { [] }
- | _ { raise (Error "Expecting space-separated strings") }
+ | _ { error lexbuf "Expecting space-separated strings" }
and blank_sep_strings = parse
| blank* '#' not_newline* newline { blank_sep_strings lexbuf }
| blank* '#' not_newline* eof { [] }
| blank* (not_blank+ as word) { word :: blank_sep_strings lexbuf }
| blank* eof { [] }
- | _ { raise (Error "Expecting blank-separated strings") }
+ | _ { error lexbuf "Expecting blank-separated strings" }
and comma_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (1)") }
+ | _ { error lexbuf "Expecting comma-separated strings (1)" }
and comma_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting comma-separated strings (2)") }
+ | _ { error lexbuf "Expecting comma-separated strings (2)" }
and comma_or_blank_sep_strings = parse
| space* (not_space_nor_comma+ as word) space* eof { [word] }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (1)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (1)" }
and comma_or_blank_sep_strings_aux = parse
| space* ',' space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* (not_space_nor_comma+ as word) { word :: comma_or_blank_sep_strings_aux lexbuf }
| space* eof { [] }
- | _ { raise (Error "Expecting (comma|blank)-separated strings (2)") }
+ | _ { error lexbuf "Expecting (comma|blank)-separated strings (2)" }
and parse_environment_path_w = parse
| ([^ ';']* as word) { word :: parse_environment_path_aux_w lexbuf }
@@ -88,7 +91,7 @@ and parse_environment_path_w = parse
and parse_environment_path_aux_w = parse
| ';' ([^ ';']* as word) { word :: parse_environment_path_aux_w lexbuf }
| eof { [] }
- | _ { raise (Error "Impossible: expecting colon-separated strings") }
+ | _ { error lexbuf "Impossible: expecting colon-separated strings" }
and parse_environment_path = parse
| ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
@@ -97,31 +100,35 @@ and parse_environment_path = parse
and parse_environment_path_aux = parse
| ':' ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Impossible: expecting colon-separated strings") }
+ | _ { error lexbuf "Impossible: expecting colon-separated strings" }
-and conf_lines dir pos err = parse
- | space* '#' not_newline* newline { conf_lines dir (pos + 1) err lexbuf }
+and conf_lines dir = parse
+ | space* '#' not_newline* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* '#' not_newline* eof { [] }
- | space* newline { conf_lines dir (pos + 1) err lexbuf }
+ | space* newline { Lexing.new_line lexbuf; conf_lines dir lexbuf }
| space* eof { [] }
| space* (not_newline_nor_colon+ as k) space* ':' space*
{
- let bexpr = Glob.parse ?dir k in
- let v1 = conf_value pos err empty lexbuf in
- let v2 = conf_values pos err v1 lexbuf in
- let rest = conf_lines dir (pos + 1) err lexbuf in (bexpr, v2) :: rest
+ let bexpr =
+ try Glob.parse ?dir k
+ with exn -> error lexbuf "Bad key %S : %s" k (Printexc.to_string exn)
+ in
+ let v1 = conf_value empty lexbuf in
+ let v2 = conf_values v1 lexbuf in
+ Lexing.new_line lexbuf; (* FIXME values may have escaped newlines *)
+ let rest = conf_lines dir lexbuf in (bexpr,v2) :: rest
}
- | _ { raise (Error(Printf.sprintf "Bad key in configuration line at line %d (from %s)" pos err)) }
+ | _ { error lexbuf "Bad key" }
-and conf_value pos err x = parse
+and conf_value x = parse
| '-' (tag as tag) { { (x) with minus_tags = tag :: x.minus_tags } }
| '+'? (tag as tag) { { (x) with plus_tags = tag :: x.plus_tags } }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad value in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad value" }
-and conf_values pos err x = parse
- | space_or_esc_nl* ',' space_or_esc_nl* { conf_values pos err (conf_value pos err x lexbuf) lexbuf }
+and conf_values x = parse
+ | space_or_esc_nl* ',' space_or_esc_nl* { conf_values (conf_value x lexbuf) lexbuf }
| (newline | eof) { x }
- | (_ | eof) { raise (Error(Printf.sprintf "Bad values in configuration line at line %d (from %s)" pos err)) }
+ | (_ | eof) { error lexbuf "Bad values" }
and path_scheme patt_allowed = parse
| ([^ '%' ]+ as prefix)
@@ -132,14 +139,13 @@ and path_scheme patt_allowed = parse
{ if patt_allowed then
let patt = My_std.String.implode (unescape (Lexing.from_string patt)) in
`Var (var, Glob.parse patt) :: path_scheme patt_allowed lexbuf
- else raise (Error(
- Printf.sprintf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)"
- var patt)) }
+ else
+ error lexbuf "Patterns are not allowed in this pathname (%%(%s:%s) only in ~prod)" var patt }
| '%'
{ `Var ("", Bool.True) :: path_scheme patt_allowed lexbuf }
| eof
{ [] }
- | _ { raise (Error("Bad pathanme scheme")) }
+ | _ { error lexbuf "Bad pathanme scheme" }
and unescape = parse
| '\\' (['(' ')'] as c) { c :: unescape lexbuf }
@@ -155,11 +161,11 @@ and ocamlfind_query = parse
"linkopts:" space* (not_newline* as lo) newline+
"location:" space* (not_newline* as l) newline+
{ n, d, v, a, lo, l }
- | _ { raise (Error "Bad ocamlfind query") }
+ | _ { error lexbuf "Bad ocamlfind query" }
and trim_blanks = parse
| blank* (not_blank* as word) blank* { word }
- | _ { raise (Error "Bad input for trim_blanks") }
+ | _ { error lexbuf "Bad input for trim_blanks" }
and tag_gen = parse
| (normal+ as name) ('(' ([^')']* as param) ')')? { name, param }
diff --git a/ocamlbuild/main.ml b/ocamlbuild/main.ml
index 3b9bd89..8a633e0 100644
--- a/ocamlbuild/main.ml
+++ b/ocamlbuild/main.ml
@@ -276,8 +276,10 @@ let main () =
| Ocaml_utils.Ocamldep_error msg ->
Log.eprintf "Ocamldep error: %s" msg;
exit rc_ocamldep_error
- | Lexers.Error msg ->
- Log.eprintf "Lexical analysis error: %s" msg;
+ | Lexers.Error (msg,pos) ->
+ let module L = Lexing in
+ Log.eprintf "%s, line %d, column %d:" pos.L.pos_fname pos.L.pos_lnum (pos.L.pos_cnum - pos.L.pos_bol);
+ Log.eprintf "Lexing error: %s" msg;
exit rc_lexing_error
| Arg.Bad msg ->
Log.eprintf "%s" msg;
diff --git a/ocamlbuild/ocaml_utils.ml b/ocamlbuild/ocaml_utils.ml
index 7726825..9ce43f1 100644
--- a/ocamlbuild/ocaml_utils.ml
+++ b/ocamlbuild/ocaml_utils.ml
@@ -144,7 +144,7 @@ let read_path_dependencies =
with_input_file depends begin fun ic ->
let ocamldep_output =
try Lexers.ocamldep_output (Lexing.from_channel ic)
- with Lexers.Error msg -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
+ with Lexers.Error (msg,_) -> raise (Ocamldep_error(Printf.sprintf "Ocamldep.ocamldep: bad output (%s)" msg)) in
let deps =
List.fold_right begin fun (path, deps) acc ->
let module_name' = module_name_of_pathname path in
|