ddperror

package
v0.2.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MSG_MISSING_RETURN         = "Am Ende einer Funktion, die etwas zurück gibt, muss eine Rückgabe Anweisung stehen"
	MSG_CHAR_LITERAL_TOO_LARGE = "Ein Buchstaben Literal darf nur einen Buchstaben enthalten"
	MSG_INVALID_UTF8           = "Der Quelltext entspricht nicht dem UTF-8 Standard"
	MSG_INVALID_FILE_EXTENSION = "Ungültiger Datei Typ (nicht .ddp)"
	MSG_GLOBAL_RETURN          = "Man kann nur aus Funktionen einen Wert zurückgeben"
)

Variables

This section is empty.

Functions

func EmptyHandler

func EmptyHandler(Error)

does nothing

func MsgAliasAlreadyExists

func MsgAliasAlreadyExists(alias, name string, isFunc bool) string

func MsgGotExpected

func MsgGotExpected(got any, expected ...any) string

generates a error message in the format

Es wurde ..., ... oder ... erwartet aber ... gefunden

func MsgNameAlreadyExists

func MsgNameAlreadyExists(name string) string

Types

type Code

type Code uint // type of an ddperror Code
const (
	SYN_UNEXPECTED_TOKEN       Code = iota + 1000 // wrong tokenType found (used in parser.consume etc.)
	SYN_EXPECTED_LITERAL                          // a literal was expected but a whole expression or other was found
	SYN_EXPECTED_IDENTIFIER                       // expected an identifier like a parameter name
	SYN_EXPECTED_TYPENAME                         // a typename was expected
	SYN_EXPECTED_CAPITAL                          // a capitalized letter was expected
	SYN_MALFORMED_LITERAL                         // a literal was malformed
	SYN_MALFORMED_INCLUDE_PATH                    // a include path was malformed or not parsable in some way
	SYN_MALFORMED_ALIAS                           // an alias is malformed syntatically (invalid tokens etc.)
	SYN_INVALID_UTF8                              // text was not valid utf8
	SYN_GENDER_MISMATCH                           // the expected and actual grammatical gender used mismatched
)

syntax error codes

const (
	SEM_NAME_ALREADY_DEFINED           Code = iota + 2000 // multiple definition of Name (duplicate variable/function names)
	SEM_NAME_UNDEFINED                                    // a function or variable name is not yet defined
	SEM_PARAM_NAME_TYPE_COUNT_MISMATCH                    // number of names and types of parameters in function declaration don't match
	SEM_EXPECTED_LINKABLE_FILEPATH                        // expected a filepath to a .c, .lib, ... file
	SEM_NON_GLOBAL_FUNCTION                               // a function was declared in a non-global scope
	SEM_MISSING_RETURN                                    // return statement in function body is missing
	SEM_MALFORMED_ALIAS                                   // an alias is malformed (too few/many parameters, too short, whatever)
	SEM_ALIAS_ALREADY_TAKEN                               // the alias already stands for another function
	SEM_ALIAS_ALREADY_DEFINED                             // the alias already stands for a different function
	SEM_ALIAS_MUST_BE_GLOBAL                              // a non-global alias declaration was found
	SEM_ALIAS_BAD_NUM_ARGS                                // invalid number of arguments (too many or too few)
	SEM_GLOBAL_RETURN                                     // a return statement outside a function was found
	SEM_BAD_NAME_CONTEXT                                  // a function name was used in place of a variable name or vice versa
	SEM_NON_GLOBAL_PUBLIC_DECL                            // a non-global variable was declared public
	SEM_NON_GLOBAL_STRUCT_DECL                            // a non-global struct was declared
	SEM_BAD_FIELD_ACCESS                                  // a non-existend field was accessed or similar
	SEM_BAD_PUBLIC_MODIFIER                               // a public modifier was missing or similar, for example in a struct decl
	SEM_BREAK_CONTINUE_NOT_IN_LOOP                        // a break or continue statement was found outside a loop
	SEM_UNKNOWN_TYPE                                      // a type was used that was not imported yet
)

semantic error codes

const (
	TYP_TYPE_MISMATCH        Code = iota + 3000 // simple type mismatch in an operator
	TYP_BAD_ASSIGNEMENT                         // invalid variable assignement
	TYP_BAD_INDEXING                            // type error in index expression
	TYP_BAD_LIST_LITERAL                        // wrong type in list literal
	TYP_BAD_CAST                                // invalid type conversion
	TYP_EXPECTED_REFERENCE                      // a variable (reference parameter) was expected
	TYP_INVALID_REFERENCE                       // a char in a string was tried to be passed as refernce
	TYP_BAD_CONDITION                           // condition value was not of type boolean
	TYP_BAD_FOR                                 // one of the expressions in a for loop was not of type int
	TYP_WRONG_RETURN_TYPE                       // the return type did not match the function signature
	TYP_BAD_FIELD_ACCESS                        // a non-struct type was accessed or similar
	TYP_PRIVATE_FIELD_ACCESS                    // a non-public field was accessed from another module
)

type error codes

const (
	MISC_INCLUDE_ERROR Code = iota
)

some errors that don't fit into any category

func (Code) ErrorPrefix

func (code Code) ErrorPrefix() string

returns the Prefix before "Fehler" of the given code Prefixes are: Syntax, Semantischer, Typ or nothing for MISC

func (Code) IsMiscError

func (code Code) IsMiscError() bool

func (Code) IsSemanticError

func (code Code) IsSemanticError() bool

func (Code) IsSyntaxError

func (code Code) IsSyntaxError() bool

func (Code) IsTypeError

func (code Code) IsTypeError() bool

type Error

type Error struct {
	Code  Code        // the error code
	Range token.Range // the range the error spans in its source
	Msg   string      // the error message
	File  string      // the filepath (or uri, url or whatever) in which the error occured
}

Error type for ddp-errors

func New

func New(code Code, Range token.Range, msg, file string) Error

create a new Error from the given parameters

func (Error) Error

func (err Error) Error() string

func (Error) String

func (err Error) String() string

simple string representation of the error should only be used for debugging the error-handlers handle the real formatting

type Handler

type Handler func(Error) // used by most ddp packages

func MakeAdvancedHandler

func MakeAdvancedHandler(file string, src []byte, w io.Writer) Handler

creates a rust-like error handler writing to w where src is the source-code from which the errors come and file is the filename where src comes from

func MakeBasicHandler

func MakeBasicHandler(w io.Writer) Handler

creates a basic handler that prints the formatted error on a line

func MakePanicHandler

func MakePanicHandler() Handler

creates a Handler that panics with the passed ddperror.Error if called

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL