Kakoune-kotlin.kak - Kotlin language support

Due date: August 18, 2019

Package

  • kotlin.kak

Module

  • kotlin.keywords
  • kdoc.keywords
  • kakoune.faces
  • kakoune.commands
  • kakoune.keys

Problem Domain

  • Minimise the use of strings with a higher level of abstraction
  • Correct indentation on keywords and tokens
  • Loosely couple modules

Requirements

Authorisation

  • Me
  • Myself, and
  • I

Scope

Limitations


Outside the scope [Future project]

keywords

inline fun <reified T : Enum<T>> enumKeywordAlternationGroup(decapitalize: Boolean): AlternationGroup {
    return enumValues<T>()
            .joinToString(prefix = "(", postfix = ")", separator = "|")
            { it.toString() }.also { when { decapitalize -> it.decapitalize() } }
}

fun keywordAlternationGroup(size: HowManyKeywords): AlternationGroup {
    require(size > 0) { "$size > 0 is false" }

    if (size < 2) return "(%s)"

    val sb = StringBuilder()

    for (k in 0 until size) {
        val isFirst = { k == 0 }
        val isLast = { k == size - 1 }

        when {
            isFirst() -> sb.append("(%s|")
            isLast()  -> sb.append("%s)")
            else      -> sb.append("%s|")
        }
    }
    return sb.toString()
}

fun String.wordBoundaryFrontAndBack() = "\\b$this\\b"

Note:
[1] Still in the design phase hoping to move into TDD next week time permitting.

@duncan kt should be a different project no?

1 Like

yep working through it will have it all sorted on projects completion. thanks alex.