OSDN Git Service

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