package k

import "github.com/alecthomas/chroma/lexers/k"

Index

Variables

var Kotlin = internal.Register(MustNewLexer(
	&Config{
		Name:      "Kotlin",
		Aliases:   []string{"kotlin"},
		Filenames: []string{"*.kt"},
		MimeTypes: []string{"text/x-kotlin"},
		DotAll:    true,
	},
	Rules{
		"root": {
			{`^\s*\[.*?\]`, NameAttribute, nil},
			{`[^\S\n]+`, Text, nil},
			{`\\\n`, Text, nil},
			{`//[^\n]*\n?`, CommentSingle, nil},
			{`/[*].*?[*]/`, CommentMultiline, nil},
			{`\n`, Text, nil},
			{`!==|!in|!is|===`, Operator, nil},
			{`%=|&&|\*=|\+\+|\+=|--|-=|->|\.\.|\/=|::|<=|==|>=|!!|!=|\|\||\?[:.]`, Operator, nil},
			{`[~!%^&*()+=|\[\]:;,.<>\/?-]`, Punctuation, nil},
			{`[{}]`, Punctuation, nil},
			{`"""`, LiteralString, Push("rawstring")},
			{`"`, LiteralStringDouble, Push("string")},
			{`(')(\\u[0-9a-fA-F]{4})(')`, ByGroups(LiteralStringChar, LiteralStringEscape, LiteralStringChar), nil},
			{`'\\.'|'[^\\]'`, LiteralStringChar, nil},
			{`0[xX][0-9a-fA-F]+[Uu]?[Ll]?|[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?[fF]?[Uu]?[Ll]?`, LiteralNumber, nil},
			{`(companion)(\s+)(object)`, ByGroups(Keyword, Text, Keyword), nil},
			{`(class|interface|object)(\s+)`, ByGroups(Keyword, Text), Push("class")},
			{`(package|import)(\s+)`, ByGroups(Keyword, Text), Push("package")},
			{`(val|var)(\s+)`, ByGroups(Keyword, Text), Push("property")},
			{`(fun)(\s+)`, ByGroups(Keyword, Text), Push("function")},
			{"" /* 506 byte string literal not displayed */, Keyword, nil},
			{`@[` + kotlinIdentifier + `]+`, NameDecorator, nil},
			{`[` + kotlinIdentifier + `]+`, Name, nil},
		},
		"package": {
			{`\S+`, NameNamespace, Pop(1)},
		},
		"class": {

			{`\x60[^\x60]+?\x60`, NameClass, Pop(1)},
			{`[` + kotlinIdentifier + `]+`, NameClass, Pop(1)},
		},
		"property": {
			{`\x60[^\x60]+?\x60`, NameProperty, Pop(1)},
			{`[` + kotlinIdentifier + `]+`, NameProperty, Pop(1)},
		},
		"generics-specification": {
			{`<`, Punctuation, Push("generics-specification")},
			{`>`, Punctuation, Pop(1)},
			{`[,:*?]`, Punctuation, nil},
			{`(in|out|reified)`, Keyword, nil},
			{`\x60[^\x60]+?\x60`, NameClass, nil},
			{`[` + kotlinIdentifier + `]+`, NameClass, nil},
			{`\s+`, Text, nil},
		},
		"function": {
			{`<`, Punctuation, Push("generics-specification")},
			{`\x60[^\x60]+?\x60`, NameFunction, Pop(1)},
			{`[` + kotlinIdentifier + `]+`, NameFunction, Pop(1)},
			{`\s+`, Text, nil},
		},
		"rawstring": {

			{`"""`, LiteralString, Pop(1)},
			{`(?:[^$"]+|\"{1,2}[^"])+`, LiteralString, nil},
			Include("string-interpol"),

			{`\$`, LiteralString, nil},
		},
		"string": {
			{`\\[tbnr'"\\\$]`, LiteralStringEscape, nil},
			{`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
			{`"`, LiteralStringDouble, Pop(1)},
			Include("string-interpol"),
			{`[^\n\\"$]+`, LiteralStringDouble, nil},

			{`\$`, LiteralStringDouble, nil},
		},
		"string-interpol": {
			{`\$[` + kotlinIdentifier + `]+`, LiteralStringInterpol, nil},
			{`\${[^}\n]*}`, LiteralStringInterpol, nil},
		},
	},
))

Kotlin lexer.

Source Files

kotlin.go

Version
v0.8.2
Published
Nov 12, 2020
Platform
js/wasm
Imports
2 packages
Last checked
1 hour ago

Tools for package owners.