diff --git a/lib/ace/mode/_test/tokens_kotlin.json b/lib/ace/mode/_test/tokens_kotlin.json index 3780132c4ba..c3098cb65f1 100644 --- a/lib/ace/mode/_test/tokens_kotlin.json +++ b/lib/ace/mode/_test/tokens_kotlin.json @@ -43,9 +43,9 @@ ],[ "start", ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","width"], + ["entity.name.variable.kotlin","width"], ["keyword.operator.declaration.kotlin",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], @@ -53,9 +53,9 @@ ],[ "start", ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","height"], + ["entity.name.variable.kotlin","height"], ["keyword.operator.declaration.kotlin",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], @@ -76,12 +76,12 @@ ["text"," "], ["paren.lparen","("], ["storage.type.buildin.kotlin","Int"], - ["punctuation.kotlin",","], + ["punctuation",","], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["paren.rparen",")"], ["text"," "], - ["keyword.operator.kotlin","->"], + ["keyword.operator.declaration.kotlin","->"], ["text"," "], ["storage.type.buildin.kotlin","Boolean"] ],[ @@ -94,21 +94,21 @@ ["text"," "], ["storage.modifier.kotlin","private"], ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","live"], + ["entity.name.variable.kotlin","live"], ["keyword.operator.declaration.kotlin",":"], ["text"," "], ["storage.type.buildin.kotlin","Array"], - ["keyword.operator.kotlin","<"], - ["storage.type.buildin.kotlin","Array"], - ["keyword.operator.kotlin","<"], - ["storage.type.buildin.kotlin","Boolean"], - ["keyword.operator.kotlin",">>"], + ["punctuation","<"], + ["storage.type.generic.kotlin","Array"], + ["punctuation","<"], + ["storage.type.generic.kotlin","Boolean"], + ["punctuation",">>"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], - ["storage.type.buildin.kotlin","Array"], + ["identifier","Array"], ["paren.lparen","("], ["identifier","height"], ["paren.rparen",")"], @@ -119,7 +119,7 @@ ["text"," "], ["keyword.operator.kotlin","->"], ["text"," "], - ["storage.type.buildin.kotlin","Array"], + ["identifier","Array"], ["paren.lparen","("], ["identifier","width"], ["paren.rparen",")"], @@ -148,18 +148,18 @@ ["text"," "], ["storage.modifier.kotlin","private"], ["text"," "], - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","liveCount"], + ["entity.name.variable.kotlin","liveCount"], ["paren.lparen","("], - ["identifier","i"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","i"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["punctuation.kotlin",","], ["text"," "], - ["identifier","j"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","j"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["paren.rparen",")"] @@ -225,18 +225,18 @@ ],[ "start", ["text"," "], - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","liveNeighbors"], + ["entity.name.variable.kotlin","liveNeighbors"], ["paren.lparen","("], - ["identifier","i"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","i"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["punctuation.kotlin",","], ["text"," "], - ["identifier","j"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","j"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["paren.rparen",")"], @@ -395,18 +395,18 @@ ["text"," "], ["storage.modifier.kotlin","operator"], ["text"," "], - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["entity.name.function.kotlin","get"], + ["entity.name.variable.kotlin","get"], ["paren.lparen","("], - ["identifier","i"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","i"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["punctuation.kotlin",","], ["text"," "], - ["identifier","j"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","j"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["paren.rparen",")"], @@ -431,7 +431,7 @@ ["text"," "], ["identifier","Test"], ["text"," "], - ["storage.modifier.kotlin","public"], + ["keyword","public"], ["text"," "], ["keyword","constructor"], ["text"," "], @@ -441,9 +441,9 @@ ["paren.rparen","}"] ],[ "start", - ["storage.modifier.kotlin","var"], + ["keyword.other.kotlin","var"], ["text"," "], - ["identifier","test"], + ["entity.name.variable.kotlin","test"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], @@ -464,19 +464,16 @@ ["comment"," */"] ],[ "start", - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","next"], + ["entity.name.variable.kotlin","next"], ["paren.lparen","("], - ["identifier","field"], - ["keyword.operator.declaration.kotlin",":"], - ["text"," "], - ["identifier","Field"], + ["variable.parameter.function.kotlin","field"], + ["keyword.operator",":"], + ["text"," Field"], ["paren.rparen",")"], ["keyword.operator.declaration.kotlin",":"], - ["text"," "], - ["identifier","Field"], - ["text"," "], + ["text"," Field "], ["paren.lparen","{"] ],[ "start", @@ -506,9 +503,9 @@ ],[ "start", ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","n"], + ["entity.name.variable.kotlin","n"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], @@ -582,17 +579,17 @@ ["comment","/** A few colony examples here */"] ],[ "start", - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","main"], + ["entity.name.variable.kotlin","main"], ["paren.lparen","("], - ["identifier","args"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","args"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Array"], - ["keyword.operator.kotlin","<"], - ["storage.type.buildin.kotlin","String"], - ["keyword.operator.kotlin",">"], + ["punctuation","<"], + ["storage.type.generic.kotlin","String"], + ["punctuation",">"], ["paren.rparen",")"], ["text"," "], ["paren.lparen","{"] @@ -803,18 +800,18 @@ "start" ],[ "start", - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","runGameOfLife"], + ["entity.name.variable.kotlin","runGameOfLife"], ["paren.lparen","("], - ["identifier","fieldText"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","fieldText"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","String"], ["punctuation.kotlin",","], ["text"," "], - ["identifier","steps"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","steps"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","Int"], ["paren.rparen",")"], @@ -823,9 +820,9 @@ ],[ "start", ["text"," "], - ["storage.modifier.kotlin","var"], + ["keyword.other.kotlin","var"], ["text"," "], - ["identifier","field"], + ["entity.name.variable.kotlin","field"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], @@ -961,26 +958,24 @@ "start" ],[ "start", - ["keyword","fun"], + ["keyword.other.kotlin","fun"], ["text"," "], - ["identifier","makeField"], + ["entity.name.variable.kotlin","makeField"], ["paren.lparen","("], - ["identifier","s"], - ["keyword.operator.declaration.kotlin",":"], + ["variable.parameter.function.kotlin","s"], + ["keyword.operator",":"], ["text"," "], ["storage.type.buildin.kotlin","String"], ["paren.rparen",")"], ["keyword.operator.declaration.kotlin",":"], - ["text"," "], - ["identifier","Field"], - ["text"," "], + ["text"," Field "], ["paren.lparen","{"] ],[ "start", ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","lines"], + ["entity.name.variable.kotlin","lines"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], @@ -1014,9 +1009,9 @@ ],[ "start", ["text"," "], - ["storage.modifier.kotlin","val"], + ["keyword.other.kotlin","val"], ["text"," "], - ["identifier","longestLine"], + ["entity.name.variable.kotlin","longestLine"], ["text"," "], ["keyword.operator.assignment.kotlin","="], ["text"," "], @@ -1035,8 +1030,8 @@ ["identifier","length"], ["text"," "], ["paren.rparen","}"], - ["text"," ?"], - ["keyword.operator.declaration.kotlin",":"], + ["text"," "], + ["keyword.operator.kotlin","?:"], ["text"," "], ["string","\"\""] ],[ diff --git a/lib/ace/mode/kotlin_highlight_rules.js b/lib/ace/mode/kotlin_highlight_rules.js index f63544a02b5..f7a9af59232 100644 --- a/lib/ace/mode/kotlin_highlight_rules.js +++ b/lib/ace/mode/kotlin_highlight_rules.js @@ -44,10 +44,7 @@ var KotlinHighlightRules = function() { + "yield|typealias|typeof|sealed|inner|value|lateinit|external|suspend|noinline|crossinline|reified|" + "expect|actual", "keyword": "companion|class|object|interface|namespace|type|fun|constructor|if|else|while|for|do|return|when|" - + "where|break|continue|try|catch|finally|throw|in|is|as|assert", - "storage.type.buildin.kotlin": "Any|Unit|String|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic|" - + "IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|Array|List|" - + "Map|Nothing|Enum|Throwable|Comparable", + + "where|break|continue|try|catch|finally|throw|in|is|as|assert|constructor", "constant.language.kotlin": "true|false|null|this|super", "entity.name.function.kotlin": "get|set" }, "identifier"); @@ -73,8 +70,44 @@ var KotlinHighlightRules = function() { include: "#expressions" }, { token: "string", - regex: /@[a-zA-Z]+\b/ - },{ + regex: /@[a-zA-Z][a-zA-Z:]*\b/ + }, { + token: ["keyword.other.kotlin", "text", "entity.name.variable.kotlin"], + regex: /\b(var|val)(\s+)([a-zA-Z_][\w]*)\b/ + }, { + token: ["keyword.other.kotlin", "text", "entity.name.variable.kotlin", "paren.lparen"], + regex: /(fun)(\s+)(\w+)(\()/, + push: [{ + token: ["variable.parameter.function.kotlin", "text", "keyword.operator"], + regex: /(\w+)(\s*)(:)/ + }, { + token: "paren.rparen", + regex: /\)/, + next: "pop" + }, { + include: "#comments" + }, { + include: "#types" + }, { + include: "#expressions" + }] + }, { + token: ["text", "keyword","text", "identifier"], + regex: /^(\s*)(class)(\s*)([a-zA-Z]+)/, + next: "#classes" + }, { + token: ["identifier", "punctuaction"], + regex: /([a-zA-Z_][\w]*)(<)/, + push: [{ + include: "#generics" + }, { + include: "#defaultTypes" + }, { + token: "punctuation", + regex: />/, + next: "pop" + }] + }, { token: keywordMapper, regex: /[a-zA-Z_][\w]*\b/ }, { @@ -124,15 +157,55 @@ var KotlinHighlightRules = function() { ], regex: /^(\s*)(import)(\s+[^ $]+\s+)((?:as)?)/ }], + "#generics": [{ + token: "punctuation", + regex: //, + next: "pop" + }, { + token: "storage.type.generic.kotlin", + regex: /\w+/ + }, { + token: "keyword.operator", + regex: /:/ + }, { + token: "punctuation", + regex: /,/ + }, { + include: "#generics" + }] + }], + "#classes": [{ + include: "#generics" + }, { + token: "keyword", + regex: /public|private|constructor/ + }, { + token: "string", + regex: /@[a-zA-Z][a-zA-Z:]*\b/ + }, { + token: "text", + regex: /(?=$|\(|{)/, + next: "start" + }], "#keywords": [{ token: "keyword.operator.kotlin", - regex: /==|!=|===|!==|<=|>=|<|>|=>|->/ + regex: /==|!=|===|!==|<=|>=|<|>|=>|->|::|\?:/ }, { token: "keyword.operator.assignment.kotlin", regex: /=/ }, { token: "keyword.operator.declaration.kotlin", - regex: /:/ + regex: /:/, + push: [{ + token: "text", + regex: /(?=$|{|=|,)/, + next: "pop" + }, { + include: "#types" + }] }, { token: "keyword.operator.dot.kotlin", regex: /\./ @@ -155,6 +228,44 @@ var KotlinHighlightRules = function() { token: "punctuation.kotlin", regex: /[;,]/ }], + "#types": [{ + include: "#defaultTypes" + }, { + token: "paren.lparen", + regex: /\(/, + push: [{ + token: "paren.rparen", + regex: /\)/, + next: "pop" + }, { + include: "#defaultTypes" + }, { + token: "punctuation", + regex: /,/ + }] + }, { + include: "#generics" + }, { + token: "keyword.operator.declaration.kotlin", + regex: /->/ + }, { + token: "paren.rparen", + regex: /\)/ + }, { + token: "keyword.operator.declaration.kotlin", + regex: /:/, + push: [{ + token: "text", + regex: /(?=$|{|=|,)/, + next: "pop" + }, { + include: "#types" + }] + }], + "#defaultTypes": [{ + token: "storage.type.buildin.kotlin", + regex: /\b(Any|Unit|String|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic|IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|Array|List|Map|Nothing|Enum|Throwable|Comparable)\b/ + }], "#strings": [{ token: "string", regex: /"""/,