/
fortress_linter.py
37 lines (30 loc) · 1.2 KB
/
fortress_linter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__date__ = "$Date: 2016/02/17 $"
__license__ = "MIT"
__author__ = "Roland Siegbert <r@rscircus.org>"
import subprocess
import re
class FortranLinter:
"""Use gfortran as linter"""
def __init__(self, fileName):
self.linter = "gfortran"
self.fileName = fileName
def lint(self):
p = subprocess.Popen([self.linter,
'-fsyntax-only', # perform syntax checks only
'-Wall', # print all warnings
'-Wextra',
self.fileName],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
stdin = subprocess.PIPE)
# adding group names in Python style here => better identification
catchRe = "(.+):(?P<line>\\d+):(?P<col>\\d+):((.|\\n)*)(?P<type>(Error|Warning|Note)):\\s*(?P<message>.*)"
# execute linter:
stdOut, stdErr = p.communicate()
caughtIter = re.finditer(catchRe, stdErr)
# print errors:
for el in caughtIter:
print "Line: " + el.group('line')
print "Column: " + el.group('col')
print "Errortype: " + el.group('type')
print "Message: " + el.group('message')