-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen_rules.py
38 lines (36 loc) · 887 Bytes
/
gen_rules.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
38
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
step = 0
tokenlist = None
print '<?xml version="1.0"?>'
for line in sys.stdin:
line = line.strip("\n\r")
if line.strip() == "" or line.strip()[:2] == "//":
next
ll = line.split() or [line]
l = ll[0].strip()
if l in ["style", "warning", "performance", "portability", "information", "error"]:
severity = l
step = 0
tokenlist = None
if len(ll) > 1:
tokenlist = ll[1]
else:
step += 1
if step == 2:
summary = line
print "<rule>"
if tokenlist:
print "\t<tokenlist>%s</tokenlist>" % tokenlist
print "\t<pattern><![CDATA[%s]]></pattern>" % pattern
print "\t<message>"
print "\t\t<severity>%s</severity>" % severity
if summary == "none":
print "\t\t<summary/>"
else:
print "\t\t<summary>%s</summary>" % summary
print "\t</message>"
print "</rule>"
else:
pattern = line