用于捕获来自 g++ 和 python 的错误和警告的正则表达式

Regex to capture errors and warnings from g++ and python

我最近转换到 iTerm2,最酷的功能之一是 'capture' 正则表达式的能力 - 用于捕获 compiler/interpreter 错误和警告并将它们显示在可操作的面板中,例如 IDE.

如何配置正则表达式来捕获 g++ errors/warnings 和 Python 回溯错误? Clang 抛出的错误是:

filename.c:54:9: error: use of undeclared identifier 'foo'

这导致正则表达式:

^([a-zA-Z0-9+/.-]+):([0-9]+):[0-9]+: (?:error|warning):

A Python 回溯可能是以下形式:

Traceback (most recent call last):
  File "main.py", line 664, in Run
    self.TriangulatePoints(None, show=True)
  File "main.py", line 570, in TriangulatePoints
    error = gis.triangulate()
  File "~/scripts/terrain.py", line 208, in triangulate
    if int(self.dem_data[ny][nx]) != NDV:
IndexError: index 432 is out of bounds for axis 0 with size 432

和 g++:

points_lib.cpp:70:17: note:   initializing argument 3 of ‘void CellsInCircle(int, float, int)’
 extern "C" void CellsInCircle(int maxDiameter, float cellSize, int arrayCellsInCircle)
             ^~~~~~~~~~~~~
points_lib.cpp: In function ‘void PlacePointsIO(double*, double*, int, int, char*)’:
points_lib.cpp:553:56: error: cannot convert ‘std::vector<std::vector<std::vector<int> > >’ to ‘int’ for argument ‘3’ to ‘void CellsInCircle(int, float, int)’
 CellsInCircle(maxEdge, cellSize, arrayCellsInCircle);

谢谢!我的 regex-foo 不存在。

试图包罗万象的错误、警告和提及 'line':

(?=.*(?:error|warning|line).*).*?(?<file>\w+\.\w+).*?(?<line>\d+)

(?=.*(?:error|warning|line).*) // look ahead and match one of the words possibly enclosed by white-space
.*?                            // possibly any white-space
(?<file>\w+\.\w+)              // filename with 1 char before and after dot
.*?                            // possibly any white-space
(?<line>\d+)                   // line as first sequence of digits

Demo