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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
# Module for reading and parsing Scintilla.iface file
import string
def sanitiseLine(line):
if line[-1:] == '\n': line = line[:-1]
if string.find(line, "##") != -1:
line = line[:string.find(line, "##")]
line = string.strip(line)
return line
def safename(s):
ret = s
if s == "end":
ret = "end_"
elif s=="type":
ret="type_"
elif s == "begin":
ret = "begin_"
elif s == "SetFocus":
ret = "SetFocusEx"
return ret
def decodeFunction(featureVal):
retType, rest = string.split(featureVal, " ", 1)
nameIdent, params = string.split(rest, "(")
name, value = string.split(nameIdent, "=")
if name != "":
name = safename(name)
params, rest = string.split(params, ")")
param1, param2 = string.split(params, ",")[0:2]
return retType, name, value, param1, param2
def decodeEvent(featureVal):
retType, rest = string.split(featureVal, " ", 1)
nameIdent, params = string.split(rest, "(")
name, value = string.split(nameIdent, "=")
params, rest = string.split(params, ")")
parms = ParamList()
parms.AddParams(params)
return retType, name, value, parms
def decodeParam(p):
param = string.strip(p)
type = ""
name = ""
value = ""
if " " in param:
type, nv = string.split(param, " ")
if "=" in nv:
name, value = string.split(nv, "=")
else:
name = nv
if name != "":
name = safename(name)
return type, name, value
class ParamList:
def __init__(self):
self.order = []
self.params = {}
def AddParams(self, str):
notempty = 1;
main = str
string.strip(main)
while notempty == 1:
if "," in main:
cur, main = string.split(main, ",", 1)
else:
cur = main
main = ""
t, name, v = decodeParam(cur)
if name != "":
name = safename(name)
self.params[name] = {
"ParamType" : t,
"ParamValue" : v
}
self.order.append(name)
string.strip(main)
if main == "" or main == ",":
notempty = 0
class Face:
def __init__(self):
self.order = []
self.features = {}
self.values = {}
self.events = {}
def ReadFromFile(self, name):
currentCategory = ""
currentComment = []
currentCommentFinished = 0
file = open(name)
for line in file.readlines():
line = sanitiseLine(line)
if line:
if line[0] == "#":
if line[1] == " ":
if currentCommentFinished:
currentComment = []
currentCommentFinished = 0
currentComment.append(line[2:])
else:
currentCommentFinished = 1
featureType, featureVal = string.split(line, " ", 1)
if featureType in ["fun", "get", "set"]:
retType, name, value, param1, param2 = decodeFunction(featureVal)
p1 = decodeParam(param1)
p2 = decodeParam(param2)
self.features[name] = {
"FeatureType": featureType,
"ReturnType": retType,
"Value": value,
"Param1Type": p1[0], "Param1Name": p1[1], "Param1Value": p1[2],
"Param2Type": p2[0], "Param2Name": p2[1], "Param2Value": p2[2],
"Category": currentCategory, "Comment": currentComment
}
if self.values.has_key(value):
raise "Duplicate value " + value + " " + name
self.values[value] = 1
self.order.append(name)
elif featureType == "evt":
retType, name, value, params = decodeEvent(featureVal)
p1 = decodeParam(param1)
p2 = decodeParam(param2)
self.features[name] = {
"FeatureType": featureType,
"ReturnType": retType,
"Value": value,
"Params" : params,
"Category": currentCategory, "Comment": currentComment
}
if self.events.has_key(value):
raise "Duplicate event " + value + " " + name
self.events[value] = 1
self.order.append(name)
elif featureType == "cat":
currentCategory = featureVal
elif featureType == "val":
name, value = string.split(featureVal, "=", 1)
self.features[name] = {
"FeatureType": featureType,
"Category": currentCategory,
"Value": value }
self.order.append(name)
|