2021-02-21 04:53:09 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-08-28 00:44:27 +00:00
|
|
|
# ScintillaData.py - implemented 2013 by Neil Hodgson neilh@scintilla.org
|
|
|
|
# Released to the public domain.
|
|
|
|
|
|
|
|
# Common code used by Scintilla and SciTE for source file regeneration.
|
|
|
|
# The ScintillaData object exposes information about Scintilla as properties:
|
|
|
|
# Version properties
|
|
|
|
# version
|
|
|
|
# versionDotted
|
|
|
|
# versionCommad
|
2019-05-04 18:14:48 +00:00
|
|
|
#
|
2013-08-28 00:44:27 +00:00
|
|
|
# Date last modified
|
|
|
|
# dateModified
|
|
|
|
# yearModified
|
|
|
|
# mdyModified
|
|
|
|
# dmyModified
|
|
|
|
# myModified
|
2019-05-04 18:14:48 +00:00
|
|
|
#
|
2013-08-28 00:44:27 +00:00
|
|
|
# Information about lexers and properties defined in lexers
|
|
|
|
# lexFiles
|
|
|
|
# sorted list of lexer files
|
|
|
|
# lexerModules
|
|
|
|
# sorted list of module names
|
|
|
|
# lexerProperties
|
|
|
|
# sorted list of lexer properties
|
|
|
|
# propertyDocuments
|
|
|
|
# dictionary of property documentation { name: document string }
|
2019-05-04 18:14:48 +00:00
|
|
|
# sclexFromName
|
|
|
|
# dictionary of SCLEX_* IDs { name: SCLEX_ID }
|
|
|
|
# fileFromSclex
|
|
|
|
# dictionary of file names { SCLEX_ID: file name }
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
# This file can be run to see the data it provides.
|
2021-02-21 04:53:09 +00:00
|
|
|
# Requires Python 3.6 or later
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
import datetime, pathlib, sys, textwrap
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
import FileGenerator
|
|
|
|
|
|
|
|
def FindModules(lexFile):
|
|
|
|
modules = []
|
2019-05-04 18:14:48 +00:00
|
|
|
partLine = ""
|
2021-02-21 04:53:09 +00:00
|
|
|
with lexFile.open() as f:
|
2013-08-28 00:44:27 +00:00
|
|
|
for l in f.readlines():
|
2019-05-04 18:14:48 +00:00
|
|
|
l = l.rstrip()
|
|
|
|
if partLine or l.startswith("LexerModule"):
|
|
|
|
if ")" in l:
|
|
|
|
l = partLine + l
|
|
|
|
l = l.replace("(", " ")
|
|
|
|
l = l.replace(")", " ")
|
|
|
|
l = l.replace(",", " ")
|
|
|
|
parts = l.split()
|
|
|
|
modules.append([parts[1], parts[2], parts[4][1:-1]])
|
|
|
|
partLine = ""
|
|
|
|
else:
|
|
|
|
partLine = partLine + l
|
2013-08-28 00:44:27 +00:00
|
|
|
return modules
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
def FindLexersInXcode(xCodeProject):
|
|
|
|
lines = FileGenerator.ReadFileAsList(xCodeProject)
|
|
|
|
|
|
|
|
uidsOfBuild = {}
|
|
|
|
markersPBXBuildFile = ["Begin PBXBuildFile section", "", "End PBXBuildFile section"]
|
|
|
|
for buildLine in lines[FileGenerator.FindSectionInList(lines, markersPBXBuildFile)]:
|
|
|
|
# Occurs for each file in the build. Find the UIDs used for the file.
|
|
|
|
#\t\t[0-9A-F]+ /* [a-zA-Z]+.cxx in sources */ = {isa = PBXBuildFile; fileRef = [0-9A-F]+ /* [a-zA-Z]+ */; };
|
|
|
|
pieces = buildLine.split()
|
|
|
|
uid1 = pieces[0]
|
|
|
|
filename = pieces[2].split(".")[0]
|
|
|
|
uid2 = pieces[12]
|
|
|
|
uidsOfBuild[filename] = [uid1, uid2]
|
|
|
|
|
|
|
|
lexers = {}
|
|
|
|
markersLexers = ["/* Lexers */ =", "children", ");"]
|
|
|
|
for lexerLine in lines[FileGenerator.FindSectionInList(lines, markersLexers)]:
|
|
|
|
#\t\t\t\t[0-9A-F]+ /* [a-zA-Z]+.cxx */,
|
|
|
|
uid, _, rest = lexerLine.partition("/* ")
|
|
|
|
uid = uid.strip()
|
|
|
|
lexer, _, _ = rest.partition(".")
|
|
|
|
lexers[lexer] = uidsOfBuild[lexer]
|
|
|
|
|
|
|
|
return lexers
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
# Properties that start with lexer. or fold. are automatically found but there are some
|
|
|
|
# older properties that don't follow this pattern so must be explicitly listed.
|
|
|
|
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"
|
|
|
|
]
|
|
|
|
|
|
|
|
def FindProperties(lexFile):
|
|
|
|
properties = {}
|
|
|
|
with open(lexFile) as f:
|
|
|
|
for l in f.readlines():
|
|
|
|
if ("GetProperty" in l or "DefineProperty" in l) and "\"" 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[propertyName] = 1
|
|
|
|
return properties
|
|
|
|
|
|
|
|
def FindPropertyDocumentation(lexFile):
|
|
|
|
documents = {}
|
2021-02-21 04:53:09 +00:00
|
|
|
with lexFile.open() as f:
|
2013-08-28 00:44:27 +00:00
|
|
|
name = ""
|
|
|
|
for l in f.readlines():
|
|
|
|
l = l.strip()
|
|
|
|
if "// property " in l:
|
|
|
|
propertyName = l.split()[2]
|
|
|
|
if propertyName.lower() == propertyName:
|
|
|
|
# Only allow lower case property names
|
|
|
|
name = propertyName
|
|
|
|
documents[name] = ""
|
|
|
|
elif "DefineProperty" in l and "\"" in l:
|
|
|
|
propertyName = l.split("\"")[1]
|
|
|
|
if propertyName.lower() == propertyName:
|
|
|
|
# Only allow lower case property names
|
|
|
|
name = propertyName
|
|
|
|
documents[name] = ""
|
|
|
|
elif name:
|
|
|
|
if l.startswith("//"):
|
|
|
|
if documents[name]:
|
|
|
|
documents[name] += " "
|
|
|
|
documents[name] += l[2:].strip()
|
|
|
|
elif l.startswith("\""):
|
|
|
|
l = l[1:].strip()
|
|
|
|
if l.endswith(";"):
|
|
|
|
l = l[:-1].strip()
|
|
|
|
if l.endswith(")"):
|
|
|
|
l = l[:-1].strip()
|
|
|
|
if l.endswith("\""):
|
|
|
|
l = l[:-1]
|
|
|
|
# Fix escaped double quotes
|
|
|
|
l = l.replace("\\\"", "\"")
|
|
|
|
documents[name] += l
|
|
|
|
else:
|
|
|
|
name = ""
|
|
|
|
for name in list(documents.keys()):
|
|
|
|
if documents[name] == "":
|
|
|
|
del documents[name]
|
|
|
|
return documents
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
def FindCredits(historyFile):
|
|
|
|
credits = []
|
|
|
|
stage = 0
|
2021-02-21 04:53:09 +00:00
|
|
|
with historyFile.open(encoding="utf-8") as f:
|
2015-06-07 21:19:26 +00:00
|
|
|
for l in f.readlines():
|
|
|
|
l = l.strip()
|
|
|
|
if stage == 0 and l == "<table>":
|
|
|
|
stage = 1
|
|
|
|
elif stage == 1 and l == "</table>":
|
|
|
|
stage = 2
|
|
|
|
if stage == 1 and l.startswith("<td>"):
|
|
|
|
credit = l[4:-5]
|
|
|
|
if "<a" in l:
|
|
|
|
title, a, rest = credit.partition("<a href=")
|
|
|
|
urlplus, bracket, end = rest.partition(">")
|
|
|
|
name = end.split("<")[0]
|
|
|
|
url = urlplus[1:-1]
|
|
|
|
credit = title.strip()
|
|
|
|
if credit:
|
|
|
|
credit += " "
|
|
|
|
credit += name + " " + url
|
|
|
|
credits.append(credit)
|
|
|
|
return credits
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
def ciKey(a):
|
2021-02-21 04:53:09 +00:00
|
|
|
return str(a).lower()
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
def SortListInsensitive(l):
|
2021-02-21 04:53:09 +00:00
|
|
|
l.sort(key=ciKey)
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
class ScintillaData:
|
|
|
|
def __init__(self, scintillaRoot):
|
2021-02-21 04:53:09 +00:00
|
|
|
# Discover version information
|
|
|
|
self.version = (scintillaRoot / "version.txt").read_text().strip()
|
2013-08-28 00:44:27 +00:00
|
|
|
self.versionDotted = self.version[0] + '.' + self.version[1] + '.' + \
|
|
|
|
self.version[2]
|
2021-02-21 04:53:09 +00:00
|
|
|
self.versionCommad = self.versionDotted.replace(".", ", ") + ', 0'
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
with (scintillaRoot / "doc" / "index.html").open() as f:
|
2013-08-28 00:44:27 +00:00
|
|
|
self.dateModified = [l for l in f.readlines() if "Date.Modified" in l]\
|
|
|
|
[0].split('\"')[3]
|
|
|
|
# 20130602
|
|
|
|
# index.html, SciTE.html
|
|
|
|
dtModified = datetime.datetime.strptime(self.dateModified, "%Y%m%d")
|
|
|
|
self.yearModified = self.dateModified[0:4]
|
|
|
|
monthModified = dtModified.strftime("%B")
|
|
|
|
dayModified = "%d" % dtModified.day
|
|
|
|
self.mdyModified = monthModified + " " + dayModified + " " + self.yearModified
|
|
|
|
# May 22 2013
|
|
|
|
# index.html, SciTE.html
|
|
|
|
self.dmyModified = dayModified + " " + monthModified + " " + self.yearModified
|
|
|
|
# 22 May 2013
|
|
|
|
# ScintillaHistory.html -- only first should change
|
|
|
|
self.myModified = monthModified + " " + self.yearModified
|
|
|
|
|
|
|
|
# Find all the lexer source code files
|
2021-02-21 04:53:09 +00:00
|
|
|
lexFilePaths = list((scintillaRoot / "lexers").glob("Lex*.cxx"))
|
2013-08-28 00:44:27 +00:00
|
|
|
SortListInsensitive(lexFilePaths)
|
2021-02-21 04:53:09 +00:00
|
|
|
self.lexFiles = [f.stem for f in lexFilePaths]
|
2013-08-28 00:44:27 +00:00
|
|
|
self.lexerModules = []
|
|
|
|
lexerProperties = set()
|
|
|
|
self.propertyDocuments = {}
|
2019-05-04 18:14:48 +00:00
|
|
|
self.sclexFromName = {}
|
|
|
|
self.fileFromSclex = {}
|
2013-08-28 00:44:27 +00:00
|
|
|
for lexFile in lexFilePaths:
|
2019-05-04 18:14:48 +00:00
|
|
|
modules = FindModules(lexFile)
|
|
|
|
for module in modules:
|
|
|
|
self.sclexFromName[module[2]] = module[1]
|
|
|
|
self.fileFromSclex[module[1]] = lexFile
|
|
|
|
self.lexerModules.append(module[0])
|
2013-08-28 00:44:27 +00:00
|
|
|
for k in FindProperties(lexFile).keys():
|
|
|
|
lexerProperties.add(k)
|
|
|
|
documents = FindPropertyDocumentation(lexFile)
|
|
|
|
for k in documents.keys():
|
|
|
|
if k not in self.propertyDocuments:
|
|
|
|
self.propertyDocuments[k] = documents[k]
|
|
|
|
SortListInsensitive(self.lexerModules)
|
|
|
|
self.lexerProperties = list(lexerProperties)
|
|
|
|
SortListInsensitive(self.lexerProperties)
|
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
self.lexersXcode = FindLexersInXcode(scintillaRoot /
|
|
|
|
"cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj")
|
|
|
|
self.credits = FindCredits(scintillaRoot / "doc" / "ScintillaHistory.html")
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
def printWrapped(text):
|
|
|
|
print(textwrap.fill(text, subsequent_indent=" "))
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
2021-02-21 04:53:09 +00:00
|
|
|
sci = ScintillaData(pathlib.Path(__file__).resolve().parent.parent)
|
2013-08-28 00:44:27 +00:00
|
|
|
print("Version %s %s %s" % (sci.version, sci.versionDotted, sci.versionCommad))
|
|
|
|
print("Date last modified %s %s %s %s %s" % (
|
|
|
|
sci.dateModified, sci.yearModified, sci.mdyModified, sci.dmyModified, sci.myModified))
|
|
|
|
printWrapped(str(len(sci.lexFiles)) + " lexer files: " + ", ".join(sci.lexFiles))
|
|
|
|
printWrapped(str(len(sci.lexerModules)) + " lexer modules: " + ", ".join(sci.lexerModules))
|
2019-05-04 18:14:48 +00:00
|
|
|
#~ printWrapped(str(len(sci.lexersXcode)) + " Xcode lexer references: " + ", ".join(
|
|
|
|
#~ [lex+":"+uids[0]+","+uids[1] for lex, uids in sci.lexersXcode.items()]))
|
|
|
|
print("Lexer name to ID:")
|
|
|
|
lexNames = sorted(sci.sclexFromName.keys())
|
|
|
|
for lexName in lexNames:
|
|
|
|
sclex = sci.sclexFromName[lexName]
|
2021-02-21 04:53:09 +00:00
|
|
|
fileName = sci.fileFromSclex[sclex].name
|
2019-05-04 18:14:48 +00:00
|
|
|
print(" " + lexName + " -> " + sclex + " in " + fileName)
|
2013-08-28 00:44:27 +00:00
|
|
|
printWrapped("Lexer properties: " + ", ".join(sci.lexerProperties))
|
|
|
|
print("Lexer property documentation:")
|
|
|
|
documentProperties = list(sci.propertyDocuments.keys())
|
|
|
|
SortListInsensitive(documentProperties)
|
|
|
|
for k in documentProperties:
|
|
|
|
print(" " + k)
|
|
|
|
print(textwrap.fill(sci.propertyDocuments[k], initial_indent=" ",
|
|
|
|
subsequent_indent=" "))
|
2015-06-07 21:19:26 +00:00
|
|
|
print("Credits:")
|
|
|
|
for c in sci.credits:
|
2021-02-21 04:53:09 +00:00
|
|
|
sys.stdout.buffer.write(b" " + c.encode("utf-8") + b"\n")
|