TQt conversion of scintilla for Qt3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Face.py 3.2KB

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