Bladeren bron

NodeError no longer fails with empty location

Taddeus Kroes 12 jaren geleden
bovenliggende
commit
73c9cb3c80
2 gewijzigde bestanden met toevoegingen van 12 en 11 verwijderingen
  1. 0 1
      README.md
  2. 12 10
      util.ml

+ 0 - 1
README.md

@@ -9,5 +9,4 @@ Issues & TODO
 
 - Keep file content in buffer to prevent error messages from crashing when
   reading from stdin.
-- NodeError now fails on nodes without location.
 - "depth analysis" -> "index analysis"

+ 12 - 10
util.ml

@@ -336,18 +336,20 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
 let prerr_loc_msg loc msg =
     if args.verbose >= 1 then (
         let (fname, ystart, yend, xstart, xend) = loc in
-        let line_s = if yend != ystart
-            then sprintf "lines %d-%d" ystart yend
-            else sprintf "line %d" ystart
-        in
-        let char_s = if xend != xstart || yend != ystart
-            then sprintf "characters %d-%d" xstart xend
-            else sprintf "character %d" xstart
-        in
-        eprintf "File \"%s\", %s, %s:\n" fname line_s char_s;
+        if loc != noloc then (
+            let line_s = if yend != ystart
+                then sprintf "lines %d-%d" ystart yend
+                else sprintf "line %d" ystart
+            in
+            let char_s = if xend != xstart || yend != ystart
+                then sprintf "characters %d-%d" xstart xend
+                else sprintf "character %d" xstart
+            in
+            eprintf "File \"%s\", %s, %s:\n" fname line_s char_s;
+        );
         eprintf "%s\n" msg;
 
-        if args.verbose >= 2 then prerr_loc loc
+        if args.verbose >= 2 && loc != noloc then prerr_loc loc
     );
     ()