aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2007-12-30 22:03:23 +0000
committernyamatongwe <devnull@localhost>2007-12-30 22:03:23 +0000
commit60447420a049f05722584c4875feeb86bfe02c42 (patch)
tree6137fcc6cdcb08497780557602abe02aa91131d0
parent95dd55241b4b5bb841797ae110c8cb7980349cf8 (diff)
downloadscintilla-mirror-60447420a049f05722584c4875feeb86bfe02c42.tar.gz
Reindented.
-rw-r--r--src/LexGen.py344
1 files changed, 172 insertions, 172 deletions
diff --git a/src/LexGen.py b/src/LexGen.py
index 4f8e4debd..1dd11a857 100644
--- a/src/LexGen.py
+++ b/src/LexGen.py
@@ -42,195 +42,195 @@ else:
# 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, retainDefs, eolType, *lists):
- copying = 1
- listid = 0
- output = []
- for line in input.splitlines(0):
- isStartGenerated = line.startswith(commentPrefix + "++Autogenerated")
- if copying and not isStartGenerated:
- output.append(line)
- if isStartGenerated:
- if retainDefs:
- output.append(line)
- copying = 0
- definition = ""
- elif not copying and line.startswith(commentPrefix + "**"):
- if retainDefs:
- 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
- out = out.replace("\n", eolType) # correct EOLs in generated content
- output.append(out)
- elif line.startswith(commentPrefix + "--Autogenerated"):
- copying = 1
- if retainDefs:
- output.append(line)
- output = [line.rstrip(" \t") for line in output] # trim trailing whitespace
- return eolType.join(output) + eolType
+ copying = 1
+ listid = 0
+ output = []
+ for line in input.splitlines(0):
+ isStartGenerated = line.startswith(commentPrefix + "++Autogenerated")
+ if copying and not isStartGenerated:
+ output.append(line)
+ if isStartGenerated:
+ if retainDefs:
+ output.append(line)
+ copying = 0
+ definition = ""
+ elif not copying and line.startswith(commentPrefix + "**"):
+ if retainDefs:
+ 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
+ out = out.replace("\n", eolType) # correct EOLs in generated content
+ output.append(out)
+ elif line.startswith(commentPrefix + "--Autogenerated"):
+ copying = 1
+ if retainDefs:
+ output.append(line)
+ output = [line.rstrip(" \t") for line in output] # trim trailing whitespace
+ return eolType.join(output) + eolType
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. """
- try:
- infile = open(filename, "rb")
- except IOError: # File is not there yet
- out = open(filename, "wb")
- out.write(updated)
- out.close()
- print "New", filename
- return
- original = infile.read()
- infile.close()
- if updated != original:
- os.unlink(filename)
- out = open(filename, "wb")
- out.write(updated)
- out.close()
- print "Changed", filename
- #~ else:
- #~ print "Unchanged", filename
+ """ 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. """
+ try:
+ infile = open(filename, "rb")
+ except IOError: # File is not there yet
+ out = open(filename, "wb")
+ out.write(updated)
+ out.close()
+ print "New", filename
+ return
+ original = infile.read()
+ infile.close()
+ if updated != original:
+ os.unlink(filename)
+ out = open(filename, "wb")
+ out.write(updated)
+ out.close()
+ print "Changed", filename
+ #~ else:
+ #~ print "Unchanged", filename
def Generate(inpath, outpath, commentPrefix, eolType, *lists):
- """Generate 'outpath' from 'inpath'.
-
- "eolType" indicates the type of EOLs to use in the generated
- file. It should be one of following constants: LF, CRLF,
- CR, or NATIVE.
- """
- #print "generate '%s' -> '%s' (comment prefix: %r, eols: %r)"\
- # % (inpath, outpath, commentPrefix, eolType)
- try:
- infile = open(inpath, "r")
- except IOError:
- print "Can not open", inpath
- return
- original = infile.read()
- infile.close()
- updated = CopyWithInsertion(original, commentPrefix,
- inpath == outpath, eolType, *lists)
- UpdateFile(outpath, updated)
+ """Generate 'outpath' from 'inpath'.
+
+ "eolType" indicates the type of EOLs to use in the generated
+ file. It should be one of following constants: LF, CRLF,
+ CR, or NATIVE.
+ """
+ #print "generate '%s' -> '%s' (comment prefix: %r, eols: %r)"\
+ # % (inpath, outpath, commentPrefix, eolType)
+ try:
+ infile = open(inpath, "r")
+ except IOError:
+ print "Can not open", inpath
+ return
+ original = infile.read()
+ infile.close()
+ updated = CopyWithInsertion(original, commentPrefix,
+ inpath == outpath, eolType, *lists)
+ UpdateFile(outpath, updated)
def Regenerate(filename, commentPrefix, eolType, *lists):
- """Regenerate the given file.
+ """Regenerate the given file.
- "eolType" indicates the type of EOLs to use in the generated
- file. It should be one of following constants: LF, CRLF,
- CR, or NATIVE.
- """
- Generate(filename, filename, commentPrefix, eolType, *lists)
+ "eolType" indicates the type of EOLs to use in the generated
+ file. It should be one of following constants: LF, CRLF,
+ CR, or NATIVE.
+ """
+ Generate(filename, filename, commentPrefix, eolType, *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
+ modules = []
+ f = open(lexFile)
+ for l in f.readlines():
+ if l.startswith("LexerModule"):
+ l = l.replace("(", " ")
+ modules.append(l.split()[1])
+ return modules
knownIrregularProperties = [
- "fold",
- "styling.within.preprocessor",
- "tab.timmy.whinge.level",
- "asp.default.language",
- "html.tags.case.sensitive",
- "ps.level",
- "ps.tokenize",
- "sql.backslash.escapes",
- "nsis.uservars",
- "nsis.ignorecase"
+ "fold",
+ "styling.within.preprocessor",
+ "tab.timmy.whinge.level",
+ "asp.default.language",
+ "html.tags.case.sensitive",
+ "ps.level",
+ "ps.tokenize",
+ "sql.backslash.escapes",
+ "nsis.uservars",
+ "nsis.ignorecase"
]
def FindProperties(lexFile):
- properties = set()
- f = open(lexFile)
- for l in f.readlines():
- if "GetProperty" in l:
- l = l.strip()
- if not l.startswith("//"): # Drop comments
- propertyName = l.split("\"")[1]
- if propertyName.lower() == propertyName:
- # Only allow lower case property names
- if propertyName in knownIrregularProperties or \
- propertyName.startswith("fold.") or \
- propertyName.startswith("lexer."):
- properties.add(propertyName)
- return properties
+ properties = set()
+ f = open(lexFile)
+ for l in f.readlines():
+ if "GetProperty" in l:
+ l = l.strip()
+ if not l.startswith("//"): # Drop comments
+ propertyName = l.split("\"")[1]
+ if propertyName.lower() == propertyName:
+ # Only allow lower case property names
+ if propertyName in knownIrregularProperties or \
+ propertyName.startswith("fold.") or \
+ propertyName.startswith("lexer."):
+ properties.add(propertyName)
+ return properties
def ciCompare(a,b):
- return cmp(a.lower(), b.lower())
+ return cmp(a.lower(), b.lower())
def RegenerateAll():
- root="../../"
-
- # Find all the lexer source code files
- lexFilePaths = glob.glob(root + "scintilla/src/Lex*.cxx")
- lexFiles = [os.path.basename(f)[:-4] for f in lexFilePaths]
- print lexFiles
- lexerModules = []
- lexerProperties = set()
- for lexFile in lexFilePaths:
- lexerModules.extend(FindModules(lexFile))
- lexerProperties.update(FindProperties(lexFile))
- lexerModules.sort(ciCompare)
- lexerProperties.remove("fold.comment.python")
- lexerProperties = list(lexerProperties)
- lexerProperties.sort(ciCompare)
-
- # Find all the SciTE properties files
- otherProps = ["abbrev.properties", "Embedded.properties", "SciTEGlobal.properties", "SciTE.properties"]
- if os.path.exists(root + "scite"):
- propFilePaths = glob.glob(root + "scite/src/*.properties")
- propFiles = [os.path.basename(f) for f in propFilePaths if os.path.basename(f) not in otherProps]
- propFiles.sort(ciCompare)
- print propFiles
-
- Regenerate(root + "scintilla/src/KeyWords.cxx", "//", NATIVE, lexerModules)
- Regenerate(root + "scintilla/win32/makefile", "#", NATIVE, lexFiles)
- Regenerate(root + "scintilla/win32/scintilla.mak", "#", NATIVE, lexFiles)
- Regenerate(root + "scintilla/win32/scintilla_vc6.mak", "#", NATIVE, lexFiles)
- # Use Unix EOLs for gtk Makefiles so they work for Linux users when
- # extracted from the Scintilla source ZIP (typically created on
- # Windows).
- Regenerate(root + "scintilla/gtk/makefile", "#", LF, lexFiles)
- Regenerate(root + "scintilla/gtk/scintilla.mak", "#", NATIVE, lexFiles)
- Regenerate(root + "scintilla/macosx/makefile", "#", LF, lexFiles)
- if os.path.exists(root + "scite"):
- Regenerate(root + "scite/win32/makefile", "#", NATIVE, lexFiles, propFiles)
- Regenerate(root + "scite/win32/scite.mak", "#", NATIVE, lexFiles, propFiles)
- Generate(root + "scite/boundscheck/vcproj.gen",
- root + "scite/boundscheck/SciTE.vcproj", "#", NATIVE, lexFiles)
+ root="../../"
+
+ # Find all the lexer source code files
+ lexFilePaths = glob.glob(root + "scintilla/src/Lex*.cxx")
+ lexFiles = [os.path.basename(f)[:-4] for f in lexFilePaths]
+ print lexFiles
+ lexerModules = []
+ lexerProperties = set()
+ for lexFile in lexFilePaths:
+ lexerModules.extend(FindModules(lexFile))
+ lexerProperties.update(FindProperties(lexFile))
+ lexerModules.sort(ciCompare)
+ lexerProperties.remove("fold.comment.python")
+ lexerProperties = list(lexerProperties)
+ lexerProperties.sort(ciCompare)
+
+ # Find all the SciTE properties files
+ otherProps = ["abbrev.properties", "Embedded.properties", "SciTEGlobal.properties", "SciTE.properties"]
+ if os.path.exists(root + "scite"):
+ propFilePaths = glob.glob(root + "scite/src/*.properties")
+ propFiles = [os.path.basename(f) for f in propFilePaths if os.path.basename(f) not in otherProps]
+ propFiles.sort(ciCompare)
+ print propFiles
+
+ Regenerate(root + "scintilla/src/KeyWords.cxx", "//", NATIVE, lexerModules)
+ Regenerate(root + "scintilla/win32/makefile", "#", NATIVE, lexFiles)
+ Regenerate(root + "scintilla/win32/scintilla.mak", "#", NATIVE, lexFiles)
+ Regenerate(root + "scintilla/win32/scintilla_vc6.mak", "#", NATIVE, lexFiles)
+ # Use Unix EOLs for gtk Makefiles so they work for Linux users when
+ # extracted from the Scintilla source ZIP (typically created on
+ # Windows).
+ Regenerate(root + "scintilla/gtk/makefile", "#", LF, lexFiles)
+ Regenerate(root + "scintilla/gtk/scintilla.mak", "#", NATIVE, lexFiles)
+ Regenerate(root + "scintilla/macosx/makefile", "#", LF, lexFiles)
+ if os.path.exists(root + "scite"):
+ Regenerate(root + "scite/win32/makefile", "#", NATIVE, lexFiles, propFiles)
+ Regenerate(root + "scite/win32/scite.mak", "#", NATIVE, lexFiles, propFiles)
+ Generate(root + "scite/boundscheck/vcproj.gen",
+ root + "scite/boundscheck/SciTE.vcproj", "#", NATIVE, lexFiles)
RegenerateAll()