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
(* ================================================================================ *)
module Loc = struct
type t = string * int
let empty = ("Not a file", -1)
let file f = (f, -1)
let file_line f l = (f,l)
let file_opt_line fo l = match fo with
| Some f -> file_line f l
| None -> file_line "No_file" l
let file_opt_line_opt fo lo = match (fo,lo) with
| (_,Some l) -> file_opt_line fo l
| (Some f, None) -> file f
| (None, None) -> empty
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)
type t = string option * int option
let empty = (None, None)
let file f = (Some f, None)
let file_line f l = (Some f, Some l)
let file_opt_line fo l = (fo, Some l)
let file_opt_line_opt fo lo = (fo, lo)
let to_string = function
| (Some file, Some line) -> sprintf "[file: %s, line: %d]" (Filename.basename file) line
| (None, Some line) -> sprintf "[line: %d]" line
| (Some file, None) -> sprintf "[file: %s]" (Filename.basename file)
| (None, None) -> ""
end (* module Loc *)
(* ================================================================================ *)
......@@ -604,13 +597,17 @@ end (* module Timeout *)
(* ================================================================================ *)
module Global = struct
let current_file = ref "Not a file"
let current_file = ref None
let current_line = ref 1
let label_flag = 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 =
current_file := file;
current_file := Some file;
current_line := 1;
label_flag := false;
label_flag := false
end
......@@ -54,10 +54,7 @@ module Loc: sig
val file_opt_line_opt: string option -> int option -> t
val file: string -> t
val opt_set_line: int -> t option -> t option
val to_string: t -> string
val to_line: t -> int
end
......@@ -285,10 +282,12 @@ end
(* ================================================================================ *)
module Global: sig
val current_file: string ref
val current_file: string option ref
val current_line: int ref
val init: string -> unit
val label_flag: bool ref
val loc_string: unit -> string
val debug: bool ref
end
......@@ -157,7 +157,7 @@ and standard target = parse
| "file" { FILE }
| "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 }
| "without" { WITHOUT }
......@@ -174,10 +174,10 @@ and standard target = parse
| "del_feat" { DEL_FEAT }
| "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 }
| "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 }
| "sequences" { SEQUENCES }
......
......@@ -28,7 +28,7 @@ type ineq_item =
| Ineq_sofi of Ast.simple_or_feature_ident
| 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 ())
%}
......
......@@ -21,7 +21,6 @@ let get_version () = VERSION
module Loc = struct
type t = Grew_base.Loc.t
let to_string = Grew_base.Loc.to_string
let to_line = Grew_base.Loc.to_line
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