// SPDX-FileCopyrightText: 2024 Himbeer // // SPDX-License-Identifier: GPL-3.0-or-later package main import "fmt" type errAlreadyDeclared struct { name string line int } func (e errAlreadyDeclared) Error() string { return fmt.Sprintf("%d: redeclaration of %q\n", e.line, e.name) } type undeclaredKind int const ( undeclaredVariable undeclaredKind = iota undeclaredFunction undeclaredType ) func (u undeclaredKind) String() string { switch u { case undeclaredVariable: return "variable" case undeclaredFunction: return "function" case undeclaredType: return "type" default: return "identifier" } } type errUndeclared struct { name string kind undeclaredKind line int } func (e errUndeclared) Error() string { return fmt.Sprintf("%d: undeclared %s %q\n", e.line, e.kind, e.name) } type errImmutable struct { name string line int } func (e errImmutable) Error() string { return fmt.Sprintf("%d: cannot assign to constant %q\n", e.line, e.name) } type errTypeMismatch struct { expected, got cerType line int } func (e errTypeMismatch) Error() string { return fmt.Sprintf("%d: expected type %s, got %s", e.line, e.expected, e.got) } type errArgNumMismatch struct { expected, got int line int } func (e errArgNumMismatch) Error() string { return fmt.Sprintf("%d: function expects %d arguments, got %d", e.line, e.expected, e.got) }