diff options
author | Neil <nyamatongwe@gmail.com> | 2017-02-15 21:07:50 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2017-02-15 21:07:50 +1100 |
commit | 990f3dd28013b356e822fd74c1f1de578f9eff09 (patch) | |
tree | d17ff3ac064abe514784f905abac86ebc489b42a /scripts/FileGenerator.py | |
parent | 6f91daae77d449edac51aa1385e673c76b95792b (diff) | |
download | scintilla-mirror-990f3dd28013b356e822fd74c1f1de578f9eff09.tar.gz |
Automatically add new lexers to Xcode project in LexGen.py.
Diffstat (limited to 'scripts/FileGenerator.py')
-rw-r--r-- | scripts/FileGenerator.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/FileGenerator.py b/scripts/FileGenerator.py index 11d6d70ba..3d488ef13 100644 --- a/scripts/FileGenerator.py +++ b/scripts/FileGenerator.py @@ -170,6 +170,50 @@ def UpdateLineInFile(path, linePrefix, lineReplace): contents = lineEnd.join(lines) + lineEnd UpdateFile(path, contents) +def ReadFileAsList(path): + """Read all the lnes in the file and return as a list of strings without line ends. + """ + with codecs.open(path, "rU", "utf-8") as f: + return [l.rstrip('\n') for l in f] + +def UpdateFileFromLines(path, lines, lineEndToUse): + """Join the lines with the lineEndToUse then update file if the result is different. + """ + contents = lineEndToUse.join(lines) + lineEndToUse + UpdateFile(path, contents) + +def FindSectionInList(lines, markers): + """Find a section defined by an initial start marker, an optional secondary + marker and an end marker. + The section is between the secondary/initial start and the end. + Report as a slice object so the section can be extracted or replaced. + Raises an exception if the markers can't be found. + """ + start = -1 + end = -1 + state = 0 + for i, l in enumerate(lines): + if markers[0] in l: + if markers[1]: + state = 1 + else: + start = i+1 + state = 2 + elif state == 1: + if markers[1] in l: + start = i+1 + state = 2 + elif state == 2: + if markers[2] in l: + end = i + state = 3 + # Check that section was found + if start == -1: + raise Exception("Could not find start marker(s) |" + markers[0] + "|" + markers[1] + "|") + if end == -1: + raise Exception("Could not find end marker " + markers[2]) + return slice(start, end) + def ReplaceREInFile(path, match, replace): with codecs.open(path, "r", "utf-8") as f: contents = f.read() |