parsers

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseParser

type BaseParser struct {
	MaxErrors int
	Lexer     lexers.Lexer
	// contains filtered or unexported fields
}

func NewBaseParser

func NewBaseParser(lexer lexers.Lexer) *BaseParser

Creates a new parser with the given lexer.

func (*BaseParser) Errors

func (p *BaseParser) Errors() []ParserError

Returns the errors found by the lexer.

func (*BaseParser) ExpectType added in v0.1.1

func (p *BaseParser) ExpectType(expected ...tokens.TokenType) bool

Checks if the next token is the given types.

func (*BaseParser) HasErrors

func (p *BaseParser) HasErrors() bool

Returns true if the lexer has errors.

func (*BaseParser) HasTooManyErrors

func (p *BaseParser) HasTooManyErrors() bool

Returns true if the lexer has too many errors.

func (*BaseParser) RegisterError added in v0.1.1

func (p *BaseParser) RegisterError(msg string)

Register an error with the given message.

func (*BaseParser) RegisterErrorWithToken added in v0.1.1

func (p *BaseParser) RegisterErrorWithToken(msg string, token *tokens.Token)

Register an error with the given message and token.

type Parser

type Parser interface {
	Errors() []ParserError
	HasErrors() bool
}

type ParserError

type ParserError struct {
	Token *tokens.Token
	Msg   string
}

func NewParserError added in v0.2.0

func NewParserError(token *tokens.Token, msg string) ParserError

Creates a new parser error with the given message.

func (ParserError) At

func (e ParserError) At() (line, column int)

Returns the initial position of the error.

func (ParserError) Error

func (e ParserError) Error() string

Returns the error message.

func (ParserError) Range added in v0.2.0

func (e ParserError) Range() (fromLine, fromColumn, toLine, toColumn int)

Returns the range of the error.

type PrattCurTokenFn

type PrattCurTokenFn func() *tokens.Token

type PrattInfixFn

type PrattInfixFn func(left asts.Node) asts.Node

type PrattIsEndOfExprFn

type PrattIsEndOfExprFn func(*tokens.Token) bool

type PrattParser

type PrattParser struct {
	*BaseParser
	IsEndOfExpr  PrattIsEndOfExprFn
	PrecedenceFn PrattPrecedenceFn
	// contains filtered or unexported fields
}

func NewPrattParser

func NewPrattParser(lexer lexers.Lexer, options ...PrattParserOption) *PrattParser

func (*PrattParser) ParseExpression

func (p *PrattParser) ParseExpression(precedence int) asts.Node

func (*PrattParser) RegisterInfixFn

func (p *PrattParser) RegisterInfixFn(tokenType tokens.TokenType, fn PrattInfixFn)

func (*PrattParser) RegisterPostfixFn

func (p *PrattParser) RegisterPostfixFn(tokenType tokens.TokenType, fn PrattPostfixFn)

func (*PrattParser) RegisterPrefixFn

func (p *PrattParser) RegisterPrefixFn(tokenType tokens.TokenType, fn PrattPrefixFn)

type PrattParserOption

type PrattParserOption func(*PrattParser)

type PrattPostfixFn

type PrattPostfixFn func() asts.Node

type PrattPrecedenceFn

type PrattPrecedenceFn func(*tokens.Token) int

type PrattPrefixFn

type PrattPrefixFn func() asts.Node

Jump to

Keyboard shortcuts

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