fix: quotes around char and str errors, added errors for assign and arrayIndex

This commit is contained in:
Barf-Vader
2025-02-06 23:52:13 +00:00
committed by Guy C
parent f24f8c87d8
commit b3ecae5dbb
2 changed files with 12 additions and 10 deletions

View File

@@ -20,12 +20,12 @@ def printError(error: Error)(using errorContent: String): Unit = {
println(
s"Duplicate declaration of identifier ${ident.v} at line: ${ident.getPosition.line} column: ${ident.getPosition.column}"
)
highlight(ident)
highlight(ident.getPosition, ident.v.length)
case Error.UndefinedIdentifier(ident, identType) =>
println(
s"Undefined ${identType.toString.toLowerCase()} ${ident.v} at line: ${ident.getPosition.line} column: ${ident.getPosition.column}"
)
highlight(ident)
highlight(ident.getPosition, ident.v.length)
case Error.FunctionParamsMismatch(ident, expected, got) =>
println(s"Function ${ident.v} expects $expected parameters, got $got")
case Error.TypeMismatch(expected, got) =>
@@ -34,13 +34,13 @@ def printError(error: Error)(using errorContent: String): Unit = {
}
def highlight(ident: ast.Ident)(using errorContent: String): Unit = {
def highlight(pos: Position, size: Int)(using errorContent: String): Unit = {
val lines = errorContent.split("\n")
val preLine = if (ident.getPosition.line > 1) lines(ident.getPosition.line - 2) else ""
val midLine = lines(ident.getPosition.line - 1)
val postLine = lines(ident.getPosition.line)
val linePointer = " " * (ident.getPosition.column) + ("^" * (ident.v.length)) + "\n"
val preLine = if (pos.line > 1) lines(pos.line - 2) else ""
val midLine = lines(pos.line - 1)
val postLine = lines(pos.line)
val linePointer = " " * (pos.column) + ("^" * (size)) + "\n"
println(
s">$preLine\n>$midLine\n$linePointer>$postLine"