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
|
# LexGen.py - implemented 2002 by Neil Hodgson neilh@scintilla.org
# Released to the public domain.
# Regenerate the Scintilla and SciTE source files that list
# all the lexers. Should be run whenever a new lexer is added or removed.
# Requires Python 2.1 or later
# The files are copied to a temporary file apart from sections between
# a ++Autogenerated comment and a --Autogenerated comment which is
# generated by the CopyWithInsertion function. After the temporary
# file is created, it is copied back to the original file name.
# Does not regenerate the Visual C++ project files.
import string
import sys
import os
import glob
# Automatically generated sections contain start and end comments,
# a definition line and the results.
# The results are replaced by regenerating based on the definition line.
# The definition line is a comment prefix followed by "**".
# If there is a digit after the ** then this indicates which list to use
# and the digit and next character are not part of the definition
# Backslash is used as an escape within the definition line.
# The part between \( and \) is repeated for each item in the list.
# \* is replaced by each list item. \t, and \n are tab and newline.
def CopyWithInsertion(input, commentPrefix, *lists):
copying = 1
listid = 0
output = []
for line in input.split("\n"):
if copying:
output.append(line)
if line.startswith(commentPrefix + "++Autogenerated"):
copying = 0
definition = ""
elif not copying and line.startswith(commentPrefix + "**"):
output.append(line)
definition = line[len(commentPrefix + "**"):]
listid = 0
if definition[0] in string.digits:
listid = int(definition[:1])
definition = definition[2:]
# Hide double slashes as a control character
definition = definition.replace("\\\\", "\001")
# Do some normal C style transforms
definition = definition.replace("\\n", "\n")
definition = definition.replace("\\t", "\t")
# Get the doubled backslashes back as single backslashes
definition = definition.replace("\001", "\\")
startRepeat = definition.find("\\(")
endRepeat = definition.find("\\)")
intro = definition[:startRepeat]
out = ""
if intro.endswith("\n"):
pos = 0
else:
pos = len(intro)
out += intro
middle = definition[startRepeat+2:endRepeat]
for i in lists[listid]:
item = middle.replace("\\*", i)
if pos and (pos + len(item) >= 80):
out += "\\\n"
pos = 0
out += item
pos += len(item)
if item.endswith("\n"):
pos = 0
outro = definition[endRepeat+2:]
out += outro
output.append(out)
elif line.startswith(commentPrefix + "--Autogenerated"):
copying = 1
output.append(line)
return "\n".join(output)
def UpdateFile(filename, updated):
""" If the file is different to updated then copy updated
into the file else leave alone so CVS and make don't treat
it as modified. """
infile = open(filename, "rb")
original = infile.read()
infile.close()
if updated != original:
os.unlink(filename)
out = open(filename, "wb")
out.write(updated)
out.close()
print "Changed", filename
def RegenerateOverLists(filename, commentPrefix, crlf, *lists):
try:
infile = open(filename, "rb")
except IOError:
print "Can not open", filename
return
original = infile.read()
infile.close()
contents = original.replace("\r\n", "\n")
updated = CopyWithInsertion(contents, commentPrefix, *lists)
if crlf:
updated = updated.replace("\n", "\r\n")
UpdateFile(filename, updated)
def Regenerate(filename, commentPrefix, *lists):
RegenerateOverLists(filename, commentPrefix, 1, *lists)
def RegenerateBinary(filename, commentPrefix, *lists):
RegenerateOverLists(filename, commentPrefix, 0, *lists)
def FindModules(lexFile):
modules = []
f = open(lexFile)
for l in f.readlines():
if l.startswith("LexerModule"):
l = l.replace("(", " ")
modules.append(l.split()[1])
return modules
root="../../"
lexFilePaths = glob.glob(root + "scintilla/src/Lex*.cxx")
lexFiles = [os.path.basename(f)[:-4] for f in lexFilePaths]
print lexFiles
lexerModules = []
for lexFile in lexFilePaths:
lexerModules.extend(FindModules(lexFile))
otherProps = ["abbrev.properties", "Embedded.properties", "SciTEGlobal.properties", "SciTE.properties"]
propFilePaths = glob.glob(root + "scite/src/*.properties")
propFiles = [os.path.basename(f) for f in propFilePaths if os.path.basename(f) not in otherProps]
print propFiles
Regenerate(root + "scintilla/src/KeyWords.cxx", "//", lexerModules)
Regenerate(root + "scintilla/win32/makefile", "#", lexFiles)
Regenerate(root + "scintilla/win32/scintilla.mak", "#", lexFiles)
Regenerate(root + "scintilla/win32/scintilla_vc6.mak", "#", lexFiles)
RegenerateBinary(root + "scintilla/gtk/makefile", "#", lexFiles)
Regenerate(root + "scintilla/gtk/scintilla.mak", "#", lexFiles)
Regenerate(root + "scite/win32/makefile", "#", lexFiles, propFiles)
Regenerate(root + "scite/win32/scite.mak", "#", lexFiles, propFiles)
|