Browse Source

use one-based error format, add -D old-error-format to keep zero-based behavior (#6391)

Nicolas Cannasse 8 years ago
parent
commit
b207d6e0d1
3 changed files with 9 additions and 1 deletions
  1. 1 0
      src/compiler/main.ml
  2. 2 0
      src/context/common.ml
  3. 6 1
      src/syntax/lexer.ml

+ 1 - 0
src/compiler/main.ml

@@ -758,6 +758,7 @@ try
 		com.warning <- if com.display.dms_error_policy = EPCollect then (fun s p -> add_diagnostics_message com s p DisplayTypes.DiagnosticsSeverity.Warning) else message ctx;
 		com.error <- error ctx;
 	end;
+	Lexer.zero_based_columns := Common.defined com Define.OldErrorFormat;
 	DisplayOutput.process_display_file com classes;
 	let ext = Initialize.initialize_target ctx com classes in
 	(* if we are at the last compilation step, allow all packages accesses - in case of macros or opening another project file *)

+ 2 - 0
src/context/common.ml

@@ -525,6 +525,7 @@ module Define = struct
 		| NoTraces
 		| Objc
 		| OldConstructorInline
+		| OldErrorFormat
 		| PhpPrefix
 		| RealPosition
 		| ReplaceFiles
@@ -627,6 +628,7 @@ module Define = struct
 		| NoTraces -> ("no_traces","Disable all trace calls")
 		| Objc -> ("objc","Sets the hxcpp output to objective-c++ classes. Must be defined for interop")
 		| OldConstructorInline -> ("old-constructor-inline","Use old constructor inlining logic (from haxe 3.4.2) instead of the reworked version.")
+		| OldErrorFormat -> ("old-error-format", "Use Haxe 3.x zero-based column error messages instead of new one-based format.")
 		| PhpPrefix -> ("php_prefix","Compiled with --php-prefix")
 		| RealPosition -> ("real_position","Disables Haxe source mapping when targetting C#, removes position comments in Java and Php7 output")
 		| ReplaceFiles -> ("replace_files","GenCommon internal")

+ 6 - 1
src/syntax/lexer.ml

@@ -196,11 +196,16 @@ let get_error_line p =
 	let l, _ = find_pos p in
 	l
 
+let zero_based_columns = ref false
+
 let get_pos_coords p =
 	let file = find_file p.pfile in
 	let l1, p1 = find_line p.pmin file in
 	let l2, p2 = find_line p.pmax file in
-	l1, p1, l2, p2
+	if !zero_based_columns then
+		l1, p1, l2, p2
+	else
+		l1, p1+1, l2, p2+1
 
 let get_error_pos printer p =
 	if p.pmin = -1 then