2017-08-24 18 views
1

我最近轉換爲iTerm2,其中最酷的功能之一是能夠捕捉正則表達式 - 對於捕獲編譯器/解釋器錯誤和警告以及將它們顯示在可執行文件面板就像一個IDE。正則表達式來捕獲來自g ++和python的錯誤和警告

如何配置正則表達式來捕獲g ++錯誤/警告和Python追溯錯誤?通過鏘引發的錯誤是:

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

這導致在正則表達式:

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

一個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); 

謝謝!我的正則表達式不存在。

+0

它是正確的嗎? – linden2015

回答

2

在包羅了所有的錯誤,警告和「行」的一提的嘗試:你想要的文件名和行

(?=.*(?: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

+0

美麗!奇妙的作品。 –