syntaxerrors

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package syntaxerrors provides tools for detecting and handling syntax errors in Solidity contracts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplaceErrorMessage

func ReplaceErrorMessage(originalMsg, oldText, newText string) string

ReplaceErrorMessage replaces a specific error message with a new message. It takes the original message, the old text to replace, and the new text, and returns the modified message.

Types

type ContextualParser

type ContextualParser struct {
	*parser.SolidityParser
	SyntaxErrorListener *SyntaxErrorListener
}

ContextualParser is a wrapper around the SolidityParser that maintains a stack of contexts. It provides methods for parsing function and contract definitions, and adds the current context to the SyntaxErrorListener.

func NewContextualParser

func NewContextualParser(tokens antlr.TokenStream, listener *SyntaxErrorListener) *ContextualParser

NewContextualParser creates a new ContextualSolidityParser. It takes a token stream and a SyntaxErrorListener, and returns a pointer to a ContextualSolidityParser.

func (*ContextualParser) SourceUnit

func (p *ContextualParser) SourceUnit() parser.ISourceUnitContext

SourceUnit parses a function definition and adds the "SourceUnit" context to the SyntaxErrorListener.

type SeverityLevel

type SeverityLevel int

SeverityLevel represents the severity of a syntax error.

const (
	// SeverityInfo represents a syntax error of informational level.
	SeverityInfo SeverityLevel = iota

	// SeverityWarning represents a syntax error of warning level.
	SeverityWarning

	// SeverityError represents a syntax error of error level.
	SeverityError
)

func (SeverityLevel) String

func (s SeverityLevel) String() string

String returns a string representation of the SeverityLevel.

type SyntaxError

type SyntaxError struct {
	Line     int
	Column   int
	Message  string
	Severity SeverityLevel
	Context  string
}

SyntaxError represents a syntax error in a Solidity contract. It includes the line and column where the error occurred, the error message, the severity of the error, and the context in which the error occurred.

func (SyntaxError) Error

func (e SyntaxError) Error() error

Error returns the error message.

type SyntaxErrorListener

type SyntaxErrorListener struct {
	*parser.BaseSolidityParserListener
	*antlr.DefaultErrorListener
	Errors []SyntaxError
	// contains filtered or unexported fields
}

SyntaxErrorListener is a listener for syntax errors in Solidity contracts. It maintains a stack of contexts and a slice of SyntaxErrors.

func NewSyntaxErrorListener

func NewSyntaxErrorListener() *SyntaxErrorListener

NewSyntaxErrorListener creates a new SyntaxErrorListener. It returns a pointer to a SyntaxErrorListener with an empty slice of SyntaxErrors and an empty stack of contexts.

func (*SyntaxErrorListener) DetermineSeverity

func (l *SyntaxErrorListener) DetermineSeverity(msg, context string) SeverityLevel

DetermineSeverity determines the severity of a syntax error. It returns the severity of the error.

func (*SyntaxErrorListener) PopContext

func (l *SyntaxErrorListener) PopContext()

PopContext removes the most recent context from the stack.

func (*SyntaxErrorListener) PushContext

func (l *SyntaxErrorListener) PushContext(ctx string)

PushContext adds a context to the stack.

func (*SyntaxErrorListener) SyntaxError

func (l *SyntaxErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)

SyntaxError handles a syntax error. It creates a new SyntaxError with the given parameters and adds it to the Errors slice.

Jump to

Keyboard shortcuts

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