Documentation
¶
Index ¶
- Constants
- func DisplayErrors(errors []PaseratiError, fallbackSource ...string)
- type CompileError
- func (e *CompileError) CausedBy(cause error) *CompileError
- func (e *CompileError) Code() string
- func (e *CompileError) Error() string
- func (e *CompileError) Kind() string
- func (e *CompileError) Message() string
- func (e *CompileError) Pos() Position
- func (e *CompileError) Unwrap() error
- func (e *CompileError) WithCode(code string) *CompileError
- type PaseratiError
- type Position
- type RuntimeError
- func (e *RuntimeError) CausedBy(cause error) *RuntimeError
- func (e *RuntimeError) Code() string
- func (e *RuntimeError) Error() string
- func (e *RuntimeError) Kind() string
- func (e *RuntimeError) Message() string
- func (e *RuntimeError) Pos() Position
- func (e *RuntimeError) Unwrap() error
- func (e *RuntimeError) WithCode(code string) *RuntimeError
- type SyntaxError
- func (e *SyntaxError) CausedBy(cause error) *SyntaxError
- func (e *SyntaxError) Code() string
- func (e *SyntaxError) Error() string
- func (e *SyntaxError) Kind() string
- func (e *SyntaxError) Message() string
- func (e *SyntaxError) Pos() Position
- func (e *SyntaxError) Unwrap() error
- func (e *SyntaxError) WithCode(code string) *SyntaxError
- type TypeError
- func NewArgumentTypeError(pos Position, argNum int, expectedType, actualType string) *TypeError
- func NewGenericConstraintError(pos Position, argType, constraintType, paramName string) *TypeError
- func NewPropertyNotExistError(pos Position, property, objectType string) *TypeError
- func NewTypeAssignmentError(pos Position, fromType, toType string) *TypeError
- func NewTypeError(pos Position, msg string, code ...string) *TypeError
- func (e *TypeError) CausedBy(cause error) *TypeError
- func (e *TypeError) Code() string
- func (e *TypeError) Error() string
- func (e *TypeError) Kind() string
- func (e *TypeError) Message() string
- func (e *TypeError) Pos() Position
- func (e *TypeError) Unwrap() error
- func (e *TypeError) WithCode(code string) *TypeError
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorCyan = "\033[36m" ColorGray = "\033[90m" ColorBold = "\033[1m" )
ANSI color codes for enhanced error formatting
const ( // Syntax Error Codes (PS1xxx) PS1001 = "PS1001" // Unexpected token PS1002 = "PS1002" // Missing token PS1003 = "PS1003" // Invalid syntax // Type Error Codes (PS2xxx) PS2001 = "PS2001" // Type assignment error PS2002 = "PS2002" // Property does not exist PS2003 = "PS2003" // Function argument type mismatch PS2004 = "PS2004" // Generic constraint violation PS2005 = "PS2005" // Type not assignable // Compile Error Codes (PS3xxx) PS3001 = "PS3001" // Compilation failed PS3002 = "PS3002" // Bytecode generation error // Runtime Error Codes (PS4xxx) PS4001 = "PS4001" // Runtime exception PS4002 = "PS4002" // Reference error )
Error codes for different types of errors (TypeScript-style)
Variables ¶
This section is empty.
Functions ¶
func DisplayErrors ¶
func DisplayErrors(errors []PaseratiError, fallbackSource ...string)
DisplayErrors prints a list of Paserati errors in TypeScript-style format with enhanced visual presentation
Types ¶
type CompileError ¶
type CompileError struct {
Position
Msg string
ErrorCode string // Error code (e.g., PS3001)
Cause error // Underlying cause, if any
}
CompileError represents an error during bytecode compilation.
func NewCompileError ¶
func NewCompileError(pos Position, msg string, code ...string) *CompileError
NewCompileError creates a new compile error with optional error code
func (*CompileError) CausedBy ¶
func (e *CompileError) CausedBy(cause error) *CompileError
func (*CompileError) Code ¶
func (e *CompileError) Code() string
func (*CompileError) Error ¶
func (e *CompileError) Error() string
func (*CompileError) Kind ¶
func (e *CompileError) Kind() string
func (*CompileError) Message ¶
func (e *CompileError) Message() string
func (*CompileError) Pos ¶
func (e *CompileError) Pos() Position
func (*CompileError) Unwrap ¶
func (e *CompileError) Unwrap() error
func (*CompileError) WithCode ¶
func (e *CompileError) WithCode(code string) *CompileError
type PaseratiError ¶
type PaseratiError interface {
error // Embed the standard error interface
Pos() Position
Kind() string // e.g., "Syntax", "Type", "Compile", "Runtime"
Code() string // Error code (e.g., "PS2001")
// Message returns the specific error message without position info.
// This might be useful if the caller wants to format the error differently.
Message() string
Unwrap() error // For error wrapping support (errors.Is/As)
}
PaseratiError is the interface implemented by all Paserati errors.
type Position ¶
type Position struct {
Line int // 1-based line number
Column int // 1-based column number (rune index within the line)
StartPos int // 0-based byte offset of the start of the token/error span
EndPos int // 0-based byte offset of the end of the token/error span (exclusive)
Source *source.SourceFile // Reference to the source file
}
Position represents a specific location in the source code. It includes line and column numbers (1-based) for human-readability, and byte offsets (0-based) for potential use in tooling (like LSP).
type RuntimeError ¶
type RuntimeError struct {
Position
Msg string
ErrorCode string // Error code (e.g., PS4001)
Cause error // Underlying cause, if any
FunctionName string // Name of the function where the error occurred (empty for script level)
FileName string // Name of the source file (if available)
}
RuntimeError represents an error during program execution in the VM.
func NewRuntimeError ¶
func NewRuntimeError(pos Position, msg string, code ...string) *RuntimeError
NewRuntimeError creates a new runtime error with optional error code
func (*RuntimeError) CausedBy ¶
func (e *RuntimeError) CausedBy(cause error) *RuntimeError
func (*RuntimeError) Code ¶
func (e *RuntimeError) Code() string
func (*RuntimeError) Error ¶
func (e *RuntimeError) Error() string
func (*RuntimeError) Kind ¶
func (e *RuntimeError) Kind() string
func (*RuntimeError) Message ¶
func (e *RuntimeError) Message() string
func (*RuntimeError) Pos ¶
func (e *RuntimeError) Pos() Position
func (*RuntimeError) Unwrap ¶
func (e *RuntimeError) Unwrap() error
func (*RuntimeError) WithCode ¶
func (e *RuntimeError) WithCode(code string) *RuntimeError
type SyntaxError ¶
type SyntaxError struct {
Position
Msg string
ErrorCode string // Error code (e.g., PS1001)
Cause error // Underlying cause, if any
}
SyntaxError represents an error during lexing or parsing.
func NewMissingTokenError ¶
func NewMissingTokenError(pos Position, expected string) *SyntaxError
NewMissingTokenError creates a missing token error (PS1002)
func NewSyntaxError ¶
func NewSyntaxError(pos Position, msg string, code ...string) *SyntaxError
NewSyntaxError creates a new syntax error with optional error code
func NewUnexpectedTokenError ¶
func NewUnexpectedTokenError(pos Position, token string) *SyntaxError
NewUnexpectedTokenError creates an unexpected token error (PS1001)
func (*SyntaxError) CausedBy ¶
func (e *SyntaxError) CausedBy(cause error) *SyntaxError
func (*SyntaxError) Code ¶
func (e *SyntaxError) Code() string
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
func (*SyntaxError) Kind ¶
func (e *SyntaxError) Kind() string
func (*SyntaxError) Message ¶
func (e *SyntaxError) Message() string
func (*SyntaxError) Pos ¶
func (e *SyntaxError) Pos() Position
func (*SyntaxError) Unwrap ¶
func (e *SyntaxError) Unwrap() error
func (*SyntaxError) WithCode ¶
func (e *SyntaxError) WithCode(code string) *SyntaxError
type TypeError ¶
type TypeError struct {
Position
Msg string
ErrorCode string // Error code (e.g., PS2001)
Cause error // Underlying cause, if any
}
TypeError represents an error during static type checking.
func NewArgumentTypeError ¶
NewArgumentTypeError creates a function argument type mismatch error (PS2003)
func NewGenericConstraintError ¶
NewGenericConstraintError creates a generic constraint violation error (PS2004)
func NewPropertyNotExistError ¶
NewPropertyNotExistError creates a property does not exist error (PS2002)
func NewTypeAssignmentError ¶
NewTypeAssignmentError creates a type assignment error (PS2001)
func NewTypeError ¶
NewTypeError creates a new type error with optional error code