Skip to content

Commit 80f3d28

Browse files
committed
fix(Bazel): Make StarlarkParser more verbose for Module.bazel issues
Signed-off-by: Mateusz Los <mateusz.los@extern.wenovate.de>
1 parent 4eccaca commit 80f3d28

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

plugins/package-managers/bazel/src/main/kotlin/StarlarkParser.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ internal data class Token(val type: TokenType, val value: String)
5757

5858
internal class Lexer(private val input: String) {
5959
private var pos = 0
60+
61+
fun locationInfo(): String {
62+
val lines = input.take(pos - 1).lines()
63+
val column = lines.last().length + 1
64+
return "line ${lines.size}, column $column: '${lines.last()}'"
65+
}
66+
6067
private val length = input.length
6168

6269
private fun peek(offset: Int = 0): Char = if (pos + offset < length) input[pos + offset] else '\u0000'
@@ -188,7 +195,10 @@ internal class Parser(input: String) {
188195
private var currentToken: Token = lexer.nextToken()
189196

190197
private fun eat(type: TokenType) {
191-
require(currentToken.type == type) { "Unexpected token: ${currentToken.type}, expected: $type" }
198+
require(currentToken.type == type) {
199+
"Unexpected token '${currentToken.value}' (${currentToken.type})" +
200+
" at ${lexer.locationInfo()}, expected: $type"
201+
}
192202
currentToken = lexer.nextToken()
193203
}
194204

0 commit comments

Comments
 (0)