aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2000-08-30 07:55:48 +0000
committernyamatongwe <devnull@localhost>2000-08-30 07:55:48 +0000
commita03d571dbd26035e86d7ab3b4236451754128b56 (patch)
tree990e882e0467e34c04f8e161bef12e43cd280f8d
parent0172574b6490efb6dfa0983047f63ba0400fc897 (diff)
downloadscintilla-mirror-a03d571dbd26035e86d7ab3b4236451754128b56.tar.gz
Initial version.
-rw-r--r--include/Face.py100
-rw-r--r--include/HFacer.py65
2 files changed, 165 insertions, 0 deletions
diff --git a/include/Face.py b/include/Face.py
new file mode 100644
index 000000000..918d07a94
--- /dev/null
+++ b/include/Face.py
@@ -0,0 +1,100 @@
+# 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 decodeFunction(featureVal):
+ retType, rest = string.split(featureVal, " ", 1)
+ nameIdent, params = string.split(rest, "(")
+ name, value = string.split(nameIdent, "=")
+ 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, "=")
+ return retType, name, value
+
+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
+ return type, name, value
+
+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 = decodeEvent(featureVal)
+ self.features[name] = {
+ "FeatureType": featureType,
+ "ReturnType": retType,
+ "Value": value,
+ "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)
+
diff --git a/include/HFacer.py b/include/HFacer.py
new file mode 100644
index 000000000..c4100fdf9
--- /dev/null
+++ b/include/HFacer.py
@@ -0,0 +1,65 @@
+import string
+import sys
+import os
+import Face
+
+def DEFINEName(ifaceName):
+ featureDefineName = string.upper(ifaceName)
+ if "_" not in featureDefineName:
+ featureDefineName = "SCI_" + featureDefineName
+ return featureDefineName
+
+def Contains(s,sub):
+ return string.find(s, sub) != -1
+
+def printLexHFile(f,out):
+ for name in f.order:
+ v = f.features[name]
+ if v["FeatureType"] in ["val"]:
+ if Contains(name, "SCE_") or Contains(name, "SCLEX_"):
+ out.write("#define " + name + " " + v["Value"] + "\n")
+
+def printHFile(f,out):
+ for name in f.order:
+ v = f.features[name]
+ if v["Category"] != "Deprecated":
+ if v["FeatureType"] in ["fun", "get", "set"]:
+ featureDefineName = "SCI_" + string.upper(name)
+ out.write("#define " + featureDefineName + " " + v["Value"] + "\n")
+ elif v["FeatureType"] in ["evt"]:
+ featureDefineName = "SCN_" + string.upper(name)
+ out.write("#define " + featureDefineName + " " + v["Value"] + "\n")
+ elif v["FeatureType"] in ["val"]:
+ if not (Contains(name, "SCE_") or Contains(name, "SCLEX_")):
+ out.write("#define " + name + " " + v["Value"] + "\n")
+
+def CopyWithInsertion(input, output, gen, definition):
+ copying = 1
+ for line in input.readlines():
+ if copying:
+ out.write(line)
+ if Contains(line, "//++Autogenerated"):
+ copying = 0
+ gen(definition, out)
+ if Contains(line, "//--Autogenerated"):
+ copying = 1
+ out.write(line)
+
+f = Face.Face()
+f.ReadFromFile("Scintilla.iface")
+
+out = open("Sci.h","w")
+hfile = open("Scintilla.h")
+CopyWithInsertion(hfile, out, printHFile, f)
+out.close()
+hfile.close()
+os.unlink("Scintilla.h")
+os.rename("Sci.h", "Scintilla.h")
+
+out = open("SciL.h","w")
+lexhfile = open("SciLexer.h")
+CopyWithInsertion(lexhfile, out, printLexHFile, f)
+out.close()
+lexhfile.close()
+os.unlink("SciLexer.h")
+os.rename("SciL.h", "SciLexer.h")