bim: Update syntax highlighters

This commit is contained in:
K. Lange 2021-03-19 11:43:58 +09:00
parent e2c10f8aa8
commit ace162ef6c
5 changed files with 18 additions and 11 deletions

View File

@ -37,13 +37,9 @@ class Highlighter(SyntaxState):
self.paint(1, self.FLAG_STRING)
def isalpha(c):
if isinstance(c,int):
if c <= 0: return False
c = chr(c)
return c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
c = c if isinstance(c,int) else ord(c)
return (c >= ord('a') and c <= ord('z')) or (c >= ord('A') and c <= ord('Z'))
def isalnum(c):
if isinstance(c,int):
if c <= 0: return False
c = chr(c)
return c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
c = c if isinstance(c,int) else ord(c)
return (c >= ord('a') and c <= ord('z')) or (c >= ord('A') and c <= ord('Z')) or (c >= ord('0') and c <= ord('9'))

View File

@ -5,6 +5,8 @@ class CHighlighter(Highlighter):
name = 'c'
extensions = ('.c','.h','.cpp','.hpp','.c++','.h++','.cc','.hh')
doxygenDocstrings = False
keywords = [
"while","if","for","continue","return","break","switch","case","sizeof",
"struct","union","typedef","do","default","else","goto",
@ -62,6 +64,8 @@ class CHighlighter(Highlighter):
else if self[0] == '\\' and self[1] == 'x':
self.paint(2, self.FLAG_ESCAPE)
while self.isxdigit(self[0]): self.paint(1, self.FLAG_ESCAPE)
else if self.doxygenDocstrings and tryDoxygenComment(self, self.FLAG_STRING):
continue
else:
last = self[0]
self.paint(1, self.FLAG_STRING)

View File

@ -14,7 +14,7 @@ class JsonHighlighter(Highlighter):
if self[0] == ':':
self.rewind(end-start)
self.paint(1, self.FLAG_ESCAPE)
while self.i < end:
while self.i < end-1:
self.paint(1, self.FLAG_KEYWORD)
if self[0] == '"':
self.paint(1, self.FLAG_ESCAPE)

View File

@ -8,17 +8,21 @@ class KrkHighlighter(Highlighter):
spaces = True
doxygenDocstrings = False
enableChecking = False
checkKrkCode = None
keywords = [
'and','class','def','else','export','for','if','in','import','let','not',
'or','return','while','try','except','raise','continue','break','as','from',
'elif', 'lambda', 'pass', 'with', 'is', 'del', 'assert', 'yield'
'elif', 'lambda', 'pass', 'with', 'is', 'del', 'assert', 'yield', 'finally',
]
types = [
'self','super','len','str','int','float','dir','repr','list','dict','range',
'object','exception','isinstance','type','print','tuple','bool','any','all',
'hex','ord','chr','bytes','set','getattr',
'hex','ord','chr','bytes','set','getattr','setattr','input','zip','enumerate',
'property','staticmethod','classmethod','filter','min','max','id','map','bin',
'sum','sorted',
]
special = [
@ -112,6 +116,7 @@ class KrkHighlighter(Highlighter):
else: self.paint(1, self.FLAG_COMMENT)
def calculate(self):
if self.enableChecking and self.i == 0: self.checkKrkCode()
if self.state <= 0:
if self[0] == '#':
self.paintDoxyComment()

View File

@ -3,6 +3,7 @@ from syntax import Highlighter, bind
class PythonHighlighter(Highlighter):
name = 'python'
extensions = ('.py',)
spaces = True
keywords = [
"class","def","return","del","if","else","elif","for","while","continue",
"break","assert","as","and","or","except","finally","from","global",
@ -18,6 +19,7 @@ class PythonHighlighter(Highlighter):
"oct","open","ord","pow","print","property","range","repr","reverse",
"round","set","setattr","slice","sorted","staticmethod","str","sum",
"super","tuple","type","vars","zip",
'self',
]
special = ['True','False','None']
def paintPyTriple(quote):