summaryrefslogtreecommitdiff
path: root/src/LispPosition.kt
blob: ea901a2fba5d6b285773a0a24a5f9798bd9f760a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package moe.nea.lisp

data class LispPosition(
    val start: Int,
    val end: Int,
    val fileName: String,
    val fileContent: String,
) : HasLispPosition {
    val startLine by lazy { fileContent.substring(0, start).count { it == '\n' } + 1 }
    val startColumn by lazy { start - fileContent.substring(0, start).indexOfLast { it == '\n' } }
    val endLine by lazy { fileContent.substring(0, end).count { it == '\n' } + 1 }
    val endColumn by lazy { end - fileContent.substring(0, end).indexOfLast { it == '\n' } }
    override val position get() = this
    override fun toString(): String {
        return "at $fileName:$startLine:$startColumn until $endLine:$endColumn"
    }
}

interface HasLispPosition {
    val position: LispPosition
}