~ubuntu-branches/ubuntu/gutsy/geany/gutsy-backports

« back to all changes in this revision

Viewing changes to scintilla/include/Face.py

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-11-19 10:51:09 UTC
  • mfrom: (8.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20071119105109-c919b7wbvrs1igyg
Tags: 0.12-1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

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