diff options
Diffstat (limited to 'src/LispPosition.kt')
-rw-r--r-- | src/LispPosition.kt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/LispPosition.kt b/src/LispPosition.kt new file mode 100644 index 0000000..ea901a2 --- /dev/null +++ b/src/LispPosition.kt @@ -0,0 +1,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 +} |