diff --git a/apps/bim.c b/apps/bim.c index c291e93b..85819c18 100644 --- a/apps/bim.c +++ b/apps/bim.c @@ -10938,7 +10938,7 @@ static KrkValue bim_krk_state_init(int argc, const KrkValue argv[], int hasKw) { *state = ((struct SyntaxState*)AS_INSTANCE(argv[1]))->state; - return argv[0]; + return NONE_VAL(); } static KrkValue krk_bim_get_commands(int argc, const KrkValue argv[], int hasKw) { diff --git a/base/usr/share/bim/syntax/graphql.krk b/base/usr/share/bim/syntax/graphql.krk new file mode 100644 index 00000000..d132760f --- /dev/null +++ b/base/usr/share/bim/syntax/graphql.krk @@ -0,0 +1,78 @@ +from syntax import Highlighter, bind +from syntax.c import CHighlighter + +class GraphqlHighlighter(Highlighter): + name = 'graphql' + extensions = ('.graphql','.gql',) + keywords = [ + 'repeatable','on','implements','extend', + 'enum','scalar','type','union','input','interface','subscription', + 'query','mutation','fragment','directive','schema', + ] + constants = [ + 'true','false','null', + '__schema','__type','__typename', + ] + primitives = [ + ] + def paintTriple(): + while self[0]: + if self[0] == "'": + self.paint(1, self.FLAG_STRING) + if self[0] == "'" and self[1] == "'": + self.paint(2, self.FLAG_STRING) + return 0 + else: + self.paint(1, self.FLAG_STRING) + return 2 + def paintPyTriple(quote): + while self[0]: + if self[0] == quote: + self.paint(1, self.FLAG_STRING) + if self[0] == quote and self[1] == quote: + self.paint(2, self.FLAG_STRING) + return 0 + else: + self.paint(1, self.FLAG_STRING) + return 1 if quote == '"' else 2 + def calculate(): + if self.state <= 0: + if self[0] == '#': + self.paintComment() + else if self[0] == '"': + if self[1] == '"' and self[2] == '"': + self.paint(3, self.FLAG_STRING) + return self.paintPyTriple('"') + self.paintSimpleString() + return 0 + else if self[0] == "'": + self.paintSingleString() + return 0 + else if self.findKeywords(self.keywords, self.FLAG_KEYWORD, self.cKeywordQualifier): + return 0 + else if self.findKeywords(self.primitives, self.FLAG_TYPE, self.cKeywordQualifier): + return 0 + else if self.findKeywords(self.constants, self.FLAG_NUMERAL, self.cKeywordQualifier): + return 0 + else if not self.cKeywordQualifier(self[-1]) and self.isdigit(self[0]): + CHighlighter.paintCNumeral(self) + return 0 + else if self[0] == '@': + self.paint(1, self.FLAG_TYPE) + while self.cKeywordQualifier(self[0]): + self.paint(1, self.FLAG_TYPE) + return 0 + else if not self.cKeywordQualifier(self[-1]) and self[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': + while self.cKeywordQualifier(self[0]): + self.paint(1, self.FLAG_TYPE) + return 0 + else if self[0]: + self.skip() + return 0 + return None + else if self.state == 1: + return self.paintPyTriple('"') + return None + +bind(GraphqlHighlighter) + diff --git a/base/usr/share/bim/syntax/java.krk b/base/usr/share/bim/syntax/java.krk index 72b89f3a..0889982f 100644 --- a/base/usr/share/bim/syntax/java.krk +++ b/base/usr/share/bim/syntax/java.krk @@ -81,35 +81,31 @@ class JavaHighlighter(Highlighter): return 1 def calculate(): if self.state <= 0: - if not self.cKeywordQualifier(self[-1]) and self.isdigit(self[0]): - CHighlighter.paintCNumeral(self) - return 0 - else if self[0] == '/' and self[1] == '/': - self.paintComment() - else if self[0] == '/' and self[1] == '*': - if self.paintJavaComment() == 1: return 1 - else if self.findKeywords(self.keywords, self.FLAG_KEYWORD, self.keywordQualifier): - return 0 - else if self.findKeywords(self.types, self.FLAG_TYPE, self.cKeywordQualifier): - return 0 - else if self.findKeywords(self.special, self.FLAG_NUMERAL, self.cKeywordQualifier): - return 0 - else if self[0] == '"': - self.paintSimpleString() - return 0 - else if self[0] == "'": - CHighlighter.paintCChar(self) - return 0 - else if self[0] == '@': - self.paint(1, self.FLAG_PRAGMA) - while self.cKeywordQualifier(self[0]): self.paint(1, self.FLAG_PRAGMA) - return 0 - else if self[0]: - self.skip() - return 0 + while self[0] is not None: + if not self.cKeywordQualifier(self[-1]) and self.isdigit(self[0]): + CHighlighter.paintCNumeral(self) + else if self[0] == '/' and self[1] == '/': + self.paintComment() + else if self[0] == '/' and self[1] == '*': + if self.paintJavaComment() == 1: return 1 + else if self.findKeywords(self.keywords, self.FLAG_KEYWORD, self.keywordQualifier): + pass + else if self.findKeywords(self.types, self.FLAG_TYPE, self.cKeywordQualifier): + pass + else if self.findKeywords(self.special, self.FLAG_NUMERAL, self.cKeywordQualifier): + pass + else if self[0] == '"': + self.paintSimpleString() + else if self[0] == "'": + CHighlighter.paintCChar(self) + else if self[0] == '@': + self.paint(1, self.FLAG_PRAGMA) + while self.cKeywordQualifier(self[0]): self.paint(1, self.FLAG_PRAGMA) + else if self[0]: + self.skip() else if self.state == 1: - if self.paintJavaComment() == 1: return 1 - return 0 + while self[0] is not None: + if self.paintJavaComment() == 1: return 1 return None bind(JavaHighlighter) diff --git a/base/usr/share/bim/syntax/krk.krk b/base/usr/share/bim/syntax/krk.krk index ade63e89..37b28a7f 100644 --- a/base/usr/share/bim/syntax/krk.krk +++ b/base/usr/share/bim/syntax/krk.krk @@ -14,7 +14,7 @@ class KrkHighlighter(Highlighter): checkKrkCode = None keywords = [ - 'and','class','def','else','export','for','if','in','import','let','not', + 'and','class','def','else','for','if','in','import','let','not', 'or','return','while','try','except','raise','continue','break','as','from', 'elif', 'lambda', 'pass', 'with', 'is', 'del', 'assert', 'yield', 'finally', 'async', 'await', diff --git a/base/usr/share/bim/syntax/make.krk b/base/usr/share/bim/syntax/make.krk index ac4bb16d..ecbd9dc2 100644 --- a/base/usr/share/bim/syntax/make.krk +++ b/base/usr/share/bim/syntax/make.krk @@ -74,7 +74,7 @@ class GnumakeHighlighter(Highlighter): self.makeVar() else: self.paint(1, self.FLAG_STRING) - def variableOrComment(flag): + def variableOrComment(flag, next): while self[0]: if self[0] == '$': self.makeVar() @@ -84,15 +84,21 @@ class GnumakeHighlighter(Highlighter): self.paintString() else if self[0] == '"': self.paintString() + else if self[0] == '\\' and not self[1]: + return next else: self.paint(1, flag) return 0 def calculate(): + if self.state == 2: + return self.variableOrComment(self.FLAG_NUMERAL, 2) + else if self.state == 3: + return self.variableOrComment(self.FLAG_NONE, 3) if self.i == 0 and self[0] == '\t': self.skip() if self[0] == '@': self.paint(1, self.FLAG_KEYWORD) - self.variableOrComment(self.FLAG_NUMERAL) + return self.variableOrComment(self.FLAG_NUMERAL, 2) else: while self[0] == ' ': self.skip() let whatisit @@ -112,7 +118,7 @@ class GnumakeHighlighter(Highlighter): else if self.findKeywords(self.commands, self.FLAG_KEYWORD, self.commandQualifier): continue else if self[0] == '$': - self.variableOrComment(self.FLAG_NONE) + self.variableOrComment(self.FLAG_NONE, 3) else: self.skip() else if whatisit == 1: # rule @@ -121,7 +127,7 @@ class GnumakeHighlighter(Highlighter): self.paintComment() else if self[0] == ':': self.paint(1, self.FLAG_TYPE) - self.variableOrComment(self.FLAG_NONE) + self.variableOrComment(self.FLAG_NONE, 3) else if self.findKeywords(self.targets, self.FLAG_KEYWORD, self.commandQualifier): continue else: @@ -132,7 +138,7 @@ class GnumakeHighlighter(Highlighter): self.paint(1, self.FLAG_TYPE) while self[0] and self[0] != '=': self.skip() - self.variableOrComment(self.FLAG_NONE) + return self.variableOrComment(self.FLAG_NONE, 3) return None bind(GnumakeHighlighter)