tint: Improve parse_hlsl_errors.py to parse DXC errors more accurately

Change-Id: Iaad6f8a9ea398f461802985504fa3423faaaa4f5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/149000
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/test/tint/parse_hlsl_errors.py b/test/tint/parse_hlsl_errors.py
index 45dd85c..e51a920 100644
--- a/test/tint/parse_hlsl_errors.py
+++ b/test/tint/parse_hlsl_errors.py
@@ -42,18 +42,26 @@
     for f in files:
         found_error = False
         with open(f, "r") as fs:
-            first_line = fs.readline()
+            all_lines = fs.readlines()
+            first_line = all_lines[0]
             if not first_line.startswith("SKIP:"):
                 continue
-            for line in fs:
-                m = re.search('error( X[0-9]+)*?:(.*)', line)
+            # The most refined errors are printed at the end, so search for error lines from bottom-up
+            all_lines.reverse()
+            for line in all_lines:
+                m = re.search('.*\.hlsl:[0-9]+:.*?(error.*)', line)
                 if m:
-                    add_error(error_to_file, m.group(), f)
+                    add_error(error_to_file, m.groups()[0], f)
                     found_error = True
                 else:
-                    if "exit status" in line:
-                        add_error(error_to_file, line, f)
+                    m = re.search('error( X[0-9]+)*?:(.*)', line)
+                    if m:
+                        add_error(error_to_file, m.group(), f)
                         found_error = True
+                    else:
+                        if "exit status" in line:
+                            add_error(error_to_file, line, f)
+                            found_error = True
                 if found_error:
                     break # Stop on first error string found