Some cleanup
[TortoiseGit.git] / ext / scintilla / include / Face.py
blob2cf4b89705110d99a4cfae7664c08d03453a4ceb
1 # Module for reading and parsing Scintilla.iface file
3 def sanitiseLine(line):
4 if line[-1:] == '\n': line = line[:-1]
5 if line.find("##") != -1:
6 line = line[:line.find("##")]
7 line = line.strip()
8 return line
10 def decodeFunction(featureVal):
11 retType, rest = featureVal.split(" ", 1)
12 nameIdent, params = rest.split("(")
13 name, value = nameIdent.split("=")
14 params, rest = params.split(")")
15 param1, param2 = params.split(",")
16 return retType, name, value, param1, param2
18 def decodeEvent(featureVal):
19 retType, rest = featureVal.split(" ", 1)
20 nameIdent, params = rest.split("(")
21 name, value = nameIdent.split("=")
22 return retType, name, value
24 def decodeParam(p):
25 param = p.strip()
26 type = ""
27 name = ""
28 value = ""
29 if " " in param:
30 type, nv = param.split(" ")
31 if "=" in nv:
32 name, value = nv.split("=")
33 else:
34 name = nv
35 return type, name, value
37 class Face:
39 def __init__(self):
40 self.order = []
41 self.features = {}
42 self.values = {}
43 self.events = {}
45 def ReadFromFile(self, name):
46 currentCategory = ""
47 currentComment = []
48 currentCommentFinished = 0
49 file = open(name)
50 for line in file.readlines():
51 line = sanitiseLine(line)
52 if line:
53 if line[0] == "#":
54 if line[1] == " ":
55 if currentCommentFinished:
56 currentComment = []
57 currentCommentFinished = 0
58 currentComment.append(line[2:])
59 else:
60 currentCommentFinished = 1
61 featureType, featureVal = line.split(" ", 1)
62 if featureType in ["fun", "get", "set"]:
63 try:
64 retType, name, value, param1, param2 = decodeFunction(featureVal)
65 except ValueError:
66 print("Failed to decode %s" % line)
67 raise
68 p1 = decodeParam(param1)
69 p2 = decodeParam(param2)
70 self.features[name] = {
71 "FeatureType": featureType,
72 "ReturnType": retType,
73 "Value": value,
74 "Param1Type": p1[0], "Param1Name": p1[1], "Param1Value": p1[2],
75 "Param2Type": p2[0], "Param2Name": p2[1], "Param2Value": p2[2],
76 "Category": currentCategory, "Comment": currentComment
78 if value in self.values:
79 raise Exception("Duplicate value " + value + " " + name)
80 self.values[value] = 1
81 self.order.append(name)
82 elif featureType == "evt":
83 retType, name, value = decodeEvent(featureVal)
84 self.features[name] = {
85 "FeatureType": featureType,
86 "ReturnType": retType,
87 "Value": value,
88 "Category": currentCategory, "Comment": currentComment
90 if value in self.events:
91 raise Exception("Duplicate event " + value + " " + name)
92 self.events[value] = 1
93 self.order.append(name)
94 elif featureType == "cat":
95 currentCategory = featureVal
96 elif featureType == "val":
97 try:
98 name, value = featureVal.split("=", 1)
99 except ValueError:
100 print("Failure %s" % featureVal)
101 raise Exception()
102 self.features[name] = {
103 "FeatureType": featureType,
104 "Category": currentCategory,
105 "Value": value }
106 self.order.append(name)
107 elif featureType == "enu" or featureType == "lex":
108 name, value = featureVal.split("=", 1)
109 self.features[name] = {
110 "FeatureType": featureType,
111 "Category": currentCategory,
112 "Value": value }
113 self.order.append(name)