| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
%% Author: Vojtěch Hořánek, <https://github.com/vojta-horanek/hisyntax-kt> |
| 3 |
|
| 4 |
\_codedecl \_hisyntaxkt {Syntax highlighting for Kotlin sources <2024-05-18>} |
| 5 |
|
| 6 |
\_newtoks \_hisyntaxkt \_newtoks \_hicolorskt |
| 7 |
|
| 8 |
\_global\_hicolorskt={ % colors for Kotlin language |
| 9 |
\_hicolor C \Grey % Comments |
| 10 |
\_hicolor D \Green % Documentation comments |
| 11 |
\_hicolor W \Yellow % Warnings |
| 12 |
\_hicolor S \Green % Strings |
| 13 |
\_hicolor K \Blue % Keywords |
| 14 |
\_hicolor F \Blue % Std. functions |
| 15 |
\_hicolor A \Yellow % Annotations |
| 16 |
\_hicolor N \Cyan % Numbers |
| 17 |
\_hicolor T \Brown % Templates |
| 18 |
\_hicolor I \Grey % Imports |
| 19 |
\_hicolor O \Magenta % Others |
| 20 |
} |
| 21 |
|
| 22 |
\_global\_hisyntaxkt={% |
| 23 |
\_the\_hicolorskt |
| 24 |
\_let\c=\_relax \_let\e=\_relax \_let\o=\_relax |
| 25 |
% comments |
| 26 |
\_replthis {FIXME} {\z W{FIXME}}% FIXME in comment |
| 27 |
\_replthis {TODO} {\z W{TODO}}% TODO in comment |
| 28 |
\_replfromto {/**}{*/} {\x D{/**#1*/}}% /**...*/ documentation |
| 29 |
\_replfromto {/*}{*/} {\x C{/*#1*/}}% /*...*/ multi-line |
| 30 |
\_replfromto {//}{^^J} {\z C{//#1}^^J}% //... single-line |
| 31 |
% strings |
| 32 |
\_replfromto {\_csstring\$\_csstring\{}{\_csstring\}}% string template expression ${tmp} |
| 33 |
{\z T{\_csstring\$\_csstring\{#1\_csstring\}}}% |
| 34 |
\_replfromto {\_csstring\$}{\n} {\x T{\_csstring\$#1}}% string template $tmp |
| 35 |
\_replthis {\_string\"} {{\_string\"}}% \" string escape |
| 36 |
\_replfromto {"}{"} {\x S{"#1"}}% "..." string |
| 37 |
% characters |
| 38 |
\_replthis {\_string\'} {{\_string\'}}% \' char escape |
| 39 |
\_replfromto {'}{'} {\x S{'#1'}}% '.' character |
| 40 |
% others |
| 41 |
\_replfromto {\n@}{\n} {\z A{@#1}}% annotations |
| 42 |
\_replfromto {package}{^^J} {\z K{package}\z I{#1}^^J}% package... |
| 43 |
\_replfromto {import}{^^J} {\z K{import}\z I{#1}^^J}% import... |
| 44 |
\_replfromto {return@}{\n} {\z K{return}\z O{@#1}}% return@... |
| 45 |
\_replfromto {continue@}{\n} {\z K{continue}\z O{@#1}}% continue@... |
| 46 |
\_replfromto {break@}{\n} {\z K{break}\z O{@#1}}% break@... |
| 47 |
% Special characters |
| 48 |
\_replthis{;}{\z C{;}} % semi-collon |
| 49 |
\_replthis{?:}{\n\o?:\n} % elvis operator |
| 50 |
\_edef\_tmpa {()\_string{\_string}+-*/=[]<>,:\_pcent\_string&|!}% non-letters |
| 51 |
\_ea \_foreach \_tmpa |
| 52 |
\_do {\_replthis{#1}{\n\o#1\n}} |
| 53 |
% |
| 54 |
\_foreach % keywords |
| 55 |
{as}{as?}{break}{class}{continue}{do}{else}{false}{for}{fun}% |
| 56 |
{if}{in}{!in}{interface}{is}{!is}{null}{object}{package}% |
| 57 |
{return}{super}{this}{throw}{true}{try}{typealias}{typeof}% |
| 58 |
{val}{var}{when}{while}{by}{catch}{constructor}{dynamic}% |
| 59 |
{finally}{get}{import}{init}{set}{value}{class}{where}% |
| 60 |
{abstract}{actual}{annotation}{companion}{const}{crossinline}% |
| 61 |
{data}{enum}{expect}{external}{final}{infix}{inline}{inner}% |
| 62 |
{internal}{lateinit}{noinline}{open}{operator}{out}{override}% |
| 63 |
{private}{protected}{public}{reified}{sealed}{suspend}{tailrec}% |
| 64 |
{vararg}{it}{equals}{compareTo}{get()}{get}{set}{set(value)}% |
| 65 |
\_do {\_replthis{\n#1\n}{\z K{#1}}} |
| 66 |
% |
| 67 |
\_foreach % standard library extension functions |
| 68 |
{all}{also}{any}{apply}{asIterable}{asSequence}{associate}% |
| 69 |
{associateBy}{associateByTo}{associateTo}{associateWith}% |
| 70 |
{associateWithTo}{average}{chunked}{contains}{count}{distinct}% |
| 71 |
{distinctBy}{drop}{dropLast}{dropLastWhile}{dropWhile}{elementAt}% |
| 72 |
{elementAtOrElse}{elementAtOrNull}{filter}{filterIndexed}% |
| 73 |
{filterIndexedTo}{filterIsInstance}{filterIsInstanceTo}{filterNot}% |
| 74 |
{filterNotNull}{filterNotNullTo}{filterNotTo}{filterTo}{find}% |
| 75 |
{findLast}{first}{firstNotNullOf}{firstNotNullOfOrNull}% |
| 76 |
{firstOrNull}{flatMap}{flatMapIndexed}{flatMapIndexedTo}% |
| 77 |
{flatMapTo}{fold}{foldIndexed}{foldRight}{foldRightIndexed}% |
| 78 |
{forEach}{forEachIndexed}{getOrElse}{getOrNull}{groupBy}% |
| 79 |
{groupByTo}{groupingBy}{indexOf}{indexOfFirst}{indexOfLast}% |
| 80 |
{intersect}{iterator}{joinTo}{joinToString}{last}{lastIndexOf}% |
| 81 |
{lastOrNull}{let}{map}{mapIndexed}{mapIndexedNotNull}% |
| 82 |
{mapIndexedNotNullTo}{mapIndexedTo}{mapNotNull}{mapNotNullTo}% |
| 83 |
{mapTo}{max}{maxBy}{maxByOrNull}{maxOf}{maxOfOrNull}{maxOfWith}% |
| 84 |
{maxOfWithOrNull}{maxOrNull}{maxWith}{maxWithOrNull}{min}{minBy}% |
| 85 |
{minByOrNull}{minOf}{minOfOrNull}{minOfWith}{minOfWithOrNull}% |
| 86 |
{minOrNull}{minus}{minusElement}{minWith}{minWithOrNull}{none}% |
| 87 |
{onEach}{onEachIndexed}{partition}{plus}{plusElement}{random}% |
| 88 |
{randomOrNull}{reduce}{reduceIndexed}{reduceIndexedOrNull}% |
| 89 |
{reduceOrNull}{reduceRight}{reduceRightIndexed}% |
| 90 |
{reduceRightIndexedOrNull}{reduceRightOrNull}{repeat}% |
| 91 |
{requireNoNulls}{reverse}{reversed}{runningFold}% |
| 92 |
{runningFoldIndexed}{runningReduce}{runningReduceIndexed}{scan}% |
| 93 |
{scanIndexed}{shuffle}{single}{singleOrNull}{slice}{sortBy}% |
| 94 |
{sortByDescending}{sortDescending}{sorted}{sortedBy}% |
| 95 |
{sortedByDescending}{sortedDescending}{sortedWith}{subtract}{sum}% |
| 96 |
{sumBy}{sumByDouble}{sumOf}{take}{takeIf}{takeLast}% |
| 97 |
{takeLastWhile}{takeUnless}{takeWhile}{toBooleanArray}% |
| 98 |
{toByteArray}{toCharArray}{toCollection}{toDoubleArray}% |
| 99 |
{toFloatArray}{toHashSet}{toIntArray}{toList}{toLongArray}% |
| 100 |
{toMutableList}{toMutableSet}{toSet}{toShortArray}{union}% |
| 101 |
{windowed}{withIndex}{zip}{zipWithNext}{contract}% |
| 102 |
\_do {\_replthis{.#1\n}{.\z F{#1}}% |
| 103 |
\_replthis{\n#1\n}{\z F{#1}}}% invoke operators ( and { begin with \n |
| 104 |
% |
| 105 |
\_replthis{.}{\n.\n} % numbers |
| 106 |
\_foreach 0123456789 |
| 107 |
\_do {\_replfromto{\n#1}{\n}{\c#1##1\e}} |
| 108 |
\_replthis{\e.\c}{.} |
| 109 |
\_replthis{\e.\n}{.\e} |
| 110 |
\_replthis{\n.\c}{\c.} |
| 111 |
\_replthis{e\e\o+\c}{e+}\_replthis{e\e\o-\c}{e-} |
| 112 |
\_replthis{E\e\o+\c}{E+}\_replthis{E\e\o-\c}{E-} |
| 113 |
\_def\c#1\e{\z N{#1}} |
| 114 |
\_def\o#1{\z O{#1}} % others |
| 115 |
} |
| 116 |
|
| 117 |
\_endcode %------------------------------------------------ |
| 118 |
|
| 119 |
|
| 120 |
\endinput |
| 121 |
|
| 122 |
2024-05-18: First version |