aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/LexGen.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/LexGen.py')
-rw-r--r--src/LexGen.py81
1 files changed, 57 insertions, 24 deletions
diff --git a/src/LexGen.py b/src/LexGen.py
index 72f7af2f4..50b088613 100644
--- a/src/LexGen.py
+++ b/src/LexGen.py
@@ -19,20 +19,28 @@ import glob
# 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, output, commentPrefix, list):
+def CopyWithInsertion(input, commentPrefix, *lists):
copying = 1
- for line in input.readlines():
+ listid = 0
+ output = []
+ for line in input.split("\n"):
if copying:
- output.write(line)
+ output.append(line)
if line.startswith(commentPrefix + "++Autogenerated"):
copying = 0
definition = ""
elif not copying and line.startswith(commentPrefix + "**"):
- output.write(line)
- definition = line[len(commentPrefix + "**"):-1]
+ 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
@@ -43,41 +51,63 @@ def CopyWithInsertion(input, output, commentPrefix, list):
startRepeat = definition.find("\\(")
endRepeat = definition.find("\\)")
intro = definition[:startRepeat]
+ out = ""
if intro.endswith("\n"):
pos = 0
else:
pos = len(intro)
- output.write(intro)
+ out += intro
middle = definition[startRepeat+2:endRepeat]
- for i in list:
+ for i in lists[listid]:
item = middle.replace("\\*", i)
if pos and (pos + len(item) >= 80):
- output.write("\\\n")
+ out += "\\\n"
pos = 0
- output.write(item)
+ out += item
pos += len(item)
if item.endswith("\n"):
pos = 0
outro = definition[endRepeat+2:]
- output.write(outro)
- output.write("\n")
+ out += outro
+ output.append(out)
elif line.startswith(commentPrefix + "--Autogenerated"):
copying = 1
- output.write(line)
+ output.append(line)
+ return "\n".join(output)
-def Regenerate(filename, commentPrefix, list, outmode="wt"):
+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, "rt")
+ infile = open(filename, "rb")
except IOError:
print "Can not open", filename
return
- tempname = filename + ".tmp"
- out = open(tempname, outmode)
- CopyWithInsertion(infile, out, commentPrefix, list)
- out.close()
+ original = infile.read()
infile.close()
- os.unlink(filename)
- os.rename(tempname, filename)
+ 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 = []
@@ -94,12 +124,15 @@ print lexFiles
lexerModules = []
for lexFile in lexFilePaths:
lexerModules.extend(FindModules(lexFile))
-print lexerModules
+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)
-Regenerate(root + "scintilla/gtk/makefile", "#", lexFiles, "wb")
+RegenerateBinary(root + "scintilla/gtk/makefile", "#", lexFiles)
Regenerate(root + "scintilla/gtk/scintilla.mak", "#", lexFiles)
-Regenerate(root + "scite/win32/makefile", "#", lexFiles)
-Regenerate(root + "scite/win32/scite.mak", "#", lexFiles)
+Regenerate(root + "scite/win32/makefile", "#", lexFiles, propFiles)
+Regenerate(root + "scite/win32/scite.mak", "#", lexFiles, propFiles)