From 209ad06f03ff1a8bd53b3e3f8e995f602b6d786e Mon Sep 17 00:00:00 2001 From: WaferJay <474346873@qq.com> Date: Sun, 3 Feb 2019 23:40:53 +0800 Subject: [PATCH] Added Kotlin language --- langs/extensions.txt | 1 + langs/kotlin/function.txt | 43 +++++++++++++++++++++++++++++++++++++ langs/kotlin/infix.txt | 8 +++++++ langs/kotlin/kotlin.txt | 29 +++++++++++++++++++++++++ langs/kotlin/modifier.txt | 26 ++++++++++++++++++++++ langs/kotlin/operator.txt | 27 +++++++++++++++++++++++ langs/kotlin/reserved.txt | 19 ++++++++++++++++ langs/kotlin/statement.txt | 17 +++++++++++++++ langs/kotlin/symbol.txt | 17 +++++++++++++++ langs/kotlin/type.txt | 44 ++++++++++++++++++++++++++++++++++++++ readme.txt | 1 + util/sample/kotlin.txt | 25 ++++++++++++++++++++++ 12 files changed, 257 insertions(+) create mode 100644 langs/kotlin/function.txt create mode 100644 langs/kotlin/infix.txt create mode 100644 langs/kotlin/kotlin.txt create mode 100644 langs/kotlin/modifier.txt create mode 100644 langs/kotlin/operator.txt create mode 100644 langs/kotlin/reserved.txt create mode 100644 langs/kotlin/statement.txt create mode 100644 langs/kotlin/symbol.txt create mode 100644 langs/kotlin/type.txt create mode 100644 util/sample/kotlin.txt diff --git a/langs/extensions.txt b/langs/extensions.txt index 61ffa0b5..7ab34f95 100644 --- a/langs/extensions.txt +++ b/langs/extensions.txt @@ -8,6 +8,7 @@ c# cs c++ h hh hpp hxx h++ cc cpp cxx c++ html html htm xhtml xhtm xml xsd java java class jar +kotlin kt mel mel ma objc m mm papyrus psc diff --git a/langs/kotlin/function.txt b/langs/kotlin/function.txt new file mode 100644 index 00000000..98777c13 --- /dev/null +++ b/langs/kotlin/function.txt @@ -0,0 +1,43 @@ +with +print +println +arrayOf +arrayOfNulls +booleanArrayOf +byteArrayOf +charArrayOf +doubleArrayOf +emptyArray +enumValueOf +enumValues +floatArrayOf +intArrayOf +longArrayOf +shortArrayOf +emptyArray +emptyList +emptySet +emptyMap +emptySequence +listOf +listOfNotNull +arrayListOf +mutableListOf +mapOf +hashMapOf +linkedMapOf +mutableMapOf +sortedMapOf +setOf +hashSetOf +linkedSetOf +mutableSetOf +sortedSetOf +assert +check +checkNotNull +error +require +requireNotNull +lazy +lazyOf \ No newline at end of file diff --git a/langs/kotlin/infix.txt b/langs/kotlin/infix.txt new file mode 100644 index 00000000..a4c5d6a6 --- /dev/null +++ b/langs/kotlin/infix.txt @@ -0,0 +1,8 @@ +shl +shr +ushr +and +xor +or +until +to \ No newline at end of file diff --git a/langs/kotlin/kotlin.txt b/langs/kotlin/kotlin.txt new file mode 100644 index 00000000..e017ec42 --- /dev/null +++ b/langs/kotlin/kotlin.txt @@ -0,0 +1,29 @@ +### KOTLIN LANGUAGE ### + +# ELEMENT_NAME [optional-css-class] REGULAR_EXPRESSION + + CASE_INSENSITIVE = OFF + + NAME Kotlin + VERSION 1.0.0 + + COMMENT (?default) + STRING (?:(?|\s*:\s*[A-Za-z_]\w*>)|(?<=in|out|:)\s+[A-Za-z_]\w*(?=>) + VARIABLE [A-Za-z_]\w*(?=\s*(?alt:operator.txt)|\s*(?alt:symbol.txt)|\s+[A-Za-z_]\w*\s+\S|\s*$) + + IDENTIFIER (?default) + + CONSTANT (?= ++= +-= +*= +/= +++ +-- +&& +|| + ++ +- +* +/ +% +? += +> +< +! \ No newline at end of file diff --git a/langs/kotlin/reserved.txt b/langs/kotlin/reserved.txt new file mode 100644 index 00000000..75adb8bc --- /dev/null +++ b/langs/kotlin/reserved.txt @@ -0,0 +1,19 @@ +package +import +typealias +class +this +super +val +get +set +var +fun +null +true +false +object +interface +typeof +init +constructor \ No newline at end of file diff --git a/langs/kotlin/statement.txt b/langs/kotlin/statement.txt new file mode 100644 index 00000000..a7a0e296 --- /dev/null +++ b/langs/kotlin/statement.txt @@ -0,0 +1,17 @@ +as +is +in +for +if +else +try +catch +finally +while +do +when +continue +break +return +throw +by \ No newline at end of file diff --git a/langs/kotlin/symbol.txt b/langs/kotlin/symbol.txt new file mode 100644 index 00000000..56f23463 --- /dev/null +++ b/langs/kotlin/symbol.txt @@ -0,0 +1,17 @@ +-> +: +! +@ +$ +% +( +) +_ +{ +} +[ +] +\ +; +, +. diff --git a/langs/kotlin/type.txt b/langs/kotlin/type.txt new file mode 100644 index 00000000..3f050318 --- /dev/null +++ b/langs/kotlin/type.txt @@ -0,0 +1,44 @@ +Any +Boolean +Int +Double +Float +Short +Number +Long +Char +String +Byte +Unit +Nothing +UByte +UInt +ULong +UShort +Array +IntArray +DoubleArray +FloatArray +ShortArray +ByteArray +CharArray +BooleanArray +LongArray +UByteArray +UIntArray +ULongArray +UShortArray +Sequence +false +null +true +Enum +Annotation +CharSequence +Comparable +Throwable +Exception +package +interface +class +Class \ No newline at end of file diff --git a/readme.txt b/readme.txt index b96d9bdd..785524ea 100644 --- a/readme.txt +++ b/readme.txt @@ -106,6 +106,7 @@ See the AssemblySys.com and ansas-meyer.de) * Java * JavaScript +* Kotlin * Objective-C * Papyrus * Perl diff --git a/util/sample/kotlin.txt b/util/sample/kotlin.txt new file mode 100644 index 00000000..91c55ffb --- /dev/null +++ b/util/sample/kotlin.txt @@ -0,0 +1,25 @@ +import kotlin.math.abs +import kotlin.math.sqrt + +data class Point(val x: Int, val y: Int) { + infix fun distance(point: Point): Double { + val dx = abs(point.x - x) + val dy = abs(point.y - y) + return sqrt(dx * dx + dy * dy.toDouble()) + } + override fun toString(): String = "($x, $y)" +} + +object Distance { + class Wrapper(private val p1: Point) { + infix fun to(p2: Point) = p1.distance(p2) + } + infix fun from(p: Point): Wrapper = Wrapper(p) +} + +fun main(args: Array) { + val p1 = Point(1, 1) + val p2 = Point(2, 2) + val dis: Double = Distance from p1 to p2 + println("The distance from $p1 to $p2 is $dis.") +} \ No newline at end of file