From 731692d95a1580465a48e20f90cfa557a2fb349e Mon Sep 17 00:00:00 2001 From: Guy C Date: Fri, 7 Feb 2025 11:59:28 +0000 Subject: [PATCH] refactor: bringing in ast and error changes --- src/main/wacc/Error.scala | 10 +++++----- src/main/wacc/ast.scala | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/wacc/Error.scala b/src/main/wacc/Error.scala index a3a5f1e..c702fd2 100644 --- a/src/main/wacc/Error.scala +++ b/src/main/wacc/Error.scala @@ -28,11 +28,11 @@ def printError(error: Error)(using errorContent: String): Unit = { s"Undefined ${identType.toString.toLowerCase()} ${ident.v}" ) highlight(ident.getPosition, ident.v.length) - case Error.FunctionParamsMismatch(ident, expected, got) => - printPosition(ident.getPosition) - println(s"Function ${ident.v} expects $expected parameters, got $got") - highlight(ident.getPosition, ident.v.length) - case Error.TypeMismatch(expected, got) => + case Error.FunctionParamsMismatch(pos, expected, got) => + printPosition(pos) + println(s"Function expects $expected parameters, got $got") + highlight(pos, 1) + case Error.TypeMismatch(pos, expected, got, msg) => println(s"Type mismatch: expected $expected, got $got") case Error.SemanticError(pos, msg) => printPosition(pos) diff --git a/src/main/wacc/ast.scala b/src/main/wacc/ast.scala index 8ea99d7..1941a16 100644 --- a/src/main/wacc/ast.scala +++ b/src/main/wacc/ast.scala @@ -30,7 +30,9 @@ object ast { object StrLiter extends ParserBridgePos1[String, StrLiter] case class PairLiter()(val pos: Position) extends Expr6 object PairLiter extends ParserBridgePos0[PairLiter] - case class Ident(v: String, var uid: Int = -1)(val pos: Position) extends Expr6 with LValue + case class Ident(v: String, var uid: Int = -1)(val pos: Position) extends Expr6 with LValue { + def getPosition: Position = pos + } object Ident extends ParserBridgePos1[String, Ident] { def apply(v: String)(pos: Position): Ident = new Ident(v)(pos) }