Commit f2405941 authored by Bruno Guillaume's avatar Bruno Guillaume

simplify location handling

parent b2f5aa46
...@@ -19,26 +19,19 @@ module Int_map = Map.Make (struct type t = int let compare = Pervasives.compare ...@@ -19,26 +19,19 @@ module Int_map = Map.Make (struct type t = int let compare = Pervasives.compare
(* ================================================================================ *) (* ================================================================================ *)
module Loc = struct module Loc = struct
type t = string * int type t = string option * int option
let empty = ("Not a file", -1) let empty = (None, None)
let file f = (f, -1) let file f = (Some f, None)
let file_line f l = (f,l) let file_line f l = (Some f, Some l)
let file_opt_line fo l = match fo with let file_opt_line fo l = (fo, Some l)
| Some f -> file_line f l let file_opt_line_opt fo lo = (fo, lo)
| None -> file_line "No_file" l
let to_string = function
let file_opt_line_opt fo lo = match (fo,lo) with | (Some file, Some line) -> sprintf "[file: %s, line: %d]" (Filename.basename file) line
| (_,Some l) -> file_opt_line fo l | (None, Some line) -> sprintf "[line: %d]" line
| (Some f, None) -> file f | (Some file, None) -> sprintf "[file: %s]" (Filename.basename file)
| (None, None) -> empty | (None, None) -> ""
let to_string (file,line) = sprintf "[file: %s, line: %d]" (Filename.basename file) line
let to_line (_,line) = line
let opt_set_line line = function
| None -> None
| Some (file,_) -> Some (file, line)
end (* module Loc *) end (* module Loc *)
(* ================================================================================ *) (* ================================================================================ *)
...@@ -604,13 +597,17 @@ end (* module Timeout *) ...@@ -604,13 +597,17 @@ end (* module Timeout *)
(* ================================================================================ *) (* ================================================================================ *)
module Global = struct module Global = struct
let current_file = ref "Not a file" let current_file = ref None
let current_line = ref 1 let current_line = ref 1
let label_flag = ref false let label_flag = ref false
let debug = ref false let debug = ref false
let loc_string () = match !current_file with
| None -> sprintf "[line %d]" !current_line
| Some f -> sprintf "[file %s, line %d]" f !current_line
let init file = let init file =
current_file := file; current_file := Some file;
current_line := 1; current_line := 1;
label_flag := false; label_flag := false
end end
...@@ -54,10 +54,7 @@ module Loc: sig ...@@ -54,10 +54,7 @@ module Loc: sig
val file_opt_line_opt: string option -> int option -> t val file_opt_line_opt: string option -> int option -> t
val file: string -> t val file: string -> t
val opt_set_line: int -> t option -> t option
val to_string: t -> string val to_string: t -> string
val to_line: t -> int
end end
...@@ -285,10 +282,12 @@ end ...@@ -285,10 +282,12 @@ end
(* ================================================================================ *) (* ================================================================================ *)
module Global: sig module Global: sig
val current_file: string ref val current_file: string option ref
val current_line: int ref val current_line: int ref
val init: string -> unit val init: string -> unit
val label_flag: bool ref val label_flag: bool ref
val loc_string: unit -> string
val debug: bool ref val debug: bool ref
end end
...@@ -157,7 +157,7 @@ and standard target = parse ...@@ -157,7 +157,7 @@ and standard target = parse
| "file" { FILE } | "file" { FILE }
| "labels" { Global.label_flag := true; LABELS } | "labels" { Global.label_flag := true; LABELS }
| "match" { Log.fwarning "[file %s, line %d]\"match\" is deprecated, please use \"pattern\" instead" !Global.current_file !Global.current_line; PATTERN } | "match" { Log.fwarning "%s \"match\" is deprecated, please use \"pattern\" instead" (Global.loc_string ()); PATTERN }
| "pattern" { PATTERN } | "pattern" { PATTERN }
| "without" { WITHOUT } | "without" { WITHOUT }
...@@ -174,10 +174,10 @@ and standard target = parse ...@@ -174,10 +174,10 @@ and standard target = parse
| "del_feat" { DEL_FEAT } | "del_feat" { DEL_FEAT }
| "module" { MODULE } | "module" { MODULE }
| "confluent" { Log.fwarning "[file %s, line %d]\"confluent\" is deprecated, please use \"deterministic\" instead" !Global.current_file !Global.current_line; DETERMINISTIC } | "confluent" { Log.fwarning "%s \"confluent\" is deprecated, please use \"deterministic\" instead" (Global.loc_string ()); DETERMINISTIC }
| "deterministic" { DETERMINISTIC } | "deterministic" { DETERMINISTIC }
| "rule" { RULE } | "rule" { RULE }
| "lex_rule" { Log.fwarning "[file %s, line %d]\"lex_rule\" is deprecated, please use \"rule\" instead" ! Global.current_file !Global.current_line; RULE } | "lex_rule" { Log.fwarning "%s \"lex_rule\" is deprecated, please use \"rule\" instead" (Global.loc_string ()); RULE }
| "filter" { FILTER } | "filter" { FILTER }
| "sequences" { SEQUENCES } | "sequences" { SEQUENCES }
......
...@@ -28,7 +28,7 @@ type ineq_item = ...@@ -28,7 +28,7 @@ type ineq_item =
| Ineq_sofi of Ast.simple_or_feature_ident | Ineq_sofi of Ast.simple_or_feature_ident
| Ineq_float of float | Ineq_float of float
let get_loc () = Loc.file_line !Global.current_file !Global.current_line let get_loc () = Loc.file_opt_line !Global.current_file !Global.current_line
let localize t = (t,get_loc ()) let localize t = (t,get_loc ())
%} %}
......
...@@ -21,7 +21,6 @@ let get_version () = VERSION ...@@ -21,7 +21,6 @@ let get_version () = VERSION
module Loc = struct module Loc = struct
type t = Grew_base.Loc.t type t = Grew_base.Loc.t
let to_string = Grew_base.Loc.to_string let to_string = Grew_base.Loc.to_string
let to_line = Grew_base.Loc.to_line
end end
(* ==================================================================================================== *) (* ==================================================================================================== *)
......
Markdown is supported
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