refactor: scaladocs-style commenting added in Error.scala
This commit is contained in:
parent
f9e5ae4d98
commit
ade1fdaffc
@ -3,6 +3,8 @@ package wacc
|
||||
import wacc.ast.Position
|
||||
import wacc.types._
|
||||
|
||||
/** Error types for semantic errors
|
||||
*/
|
||||
enum Error {
|
||||
case DuplicateDeclaration(ident: ast.Ident)
|
||||
case UndeclaredVariable(ident: ast.Ident)
|
||||
@ -14,6 +16,13 @@ enum Error {
|
||||
case InternalError(pos: Position, msg: String)
|
||||
}
|
||||
|
||||
/** Function to handle printing the details of a given semantic error
|
||||
*
|
||||
* @param error
|
||||
* Error object
|
||||
* @param errorContent
|
||||
* Contents of the file to generate code snippets
|
||||
*/
|
||||
def printError(error: Error)(using errorContent: String): Unit = {
|
||||
println("Semantic error:")
|
||||
error match {
|
||||
@ -49,6 +58,15 @@ def printError(error: Error)(using errorContent: String): Unit = {
|
||||
|
||||
}
|
||||
|
||||
/** Function to highlight a section of code for an error message
|
||||
*
|
||||
* @param pos
|
||||
* Position of the error
|
||||
* @param size
|
||||
* Size(in chars) of section to highlight
|
||||
* @param errorContent
|
||||
* Contents of the file to generate code snippets
|
||||
*/
|
||||
def highlight(pos: Position, size: Int)(using errorContent: String): Unit = {
|
||||
val lines = errorContent.split("\n")
|
||||
|
||||
@ -62,6 +80,11 @@ def highlight(pos: Position, size: Int)(using errorContent: String): Unit = {
|
||||
)
|
||||
}
|
||||
|
||||
/** Function to print the position of an error
|
||||
*
|
||||
* @param pos
|
||||
* Position of the error
|
||||
*/
|
||||
def printPosition(pos: Position): Unit = {
|
||||
println(s"(line ${pos.line}, column ${pos.column}):")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user