parser

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder[T gr.TokenTyper] struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder[T gr.TokenTyper]() Builder[T]

func (Builder[T]) Build

func (b Builder[T]) Build() Parser[T]

func (*Builder[T]) Register

func (b *Builder[T]) Register(rhs T, fn ParseFn[T])

func (*Builder[T]) Reset

func (b *Builder[T]) Reset()

type ErrUnexpectedToken

type ErrUnexpectedToken[T gr.TokenTyper] struct {
	Expected T
	After    *T
	Got      *T
}

func NewErrUnexpectedToken

func NewErrUnexpectedToken[T gr.TokenTyper](expected T, after, got *T) *ErrUnexpectedToken[T]

func (ErrUnexpectedToken[T]) Error

func (e ErrUnexpectedToken[T]) Error() string

type Item

type Item[T gr.TokenTyper] struct {
	// contains filtered or unexported fields
}

Item is an item in the parsing table.

func NewItem

func NewItem[T gr.TokenTyper](rule *Rule[T], pos int) (*Item[T], error)

NewItem creates a new item.

Parameters:

  • rule: the rule of the item.
  • pos: the position of the item in the rule.

Returns:

  • *Item: the new item.
  • error: if the position is out of range.

type ParseFn

type ParseFn[T gr.TokenTyper] func(parser *Parser[T], top1 *gr.Token[T], lookahead *gr.Token[T]) ([]*Item[T], error)

type Parser

type Parser[T gr.TokenTyper] struct {
	// contains filtered or unexported fields
}

Parser is a parser.

func (Parser[T]) Forest

func (p Parser[T]) Forest() []*gr.Token[T]

Forest returns the forest.

Returns:

  • []*gr.Token[T]: the forest.

func (*Parser[T]) Parse

func (p *Parser[T]) Parse() error

Parse parses the list of tokens.

Parameters:

  • tokens: the list of tokens.

Returns:

  • error: if an error occurred.

func (Parser[T]) Pop

func (p Parser[T]) Pop() (*gr.Token[T], bool)

Pop pops a token from the stack.

Returns:

  • grammar.Token[T]: the popped token.
  • bool: true if the token was found, false otherwise.

func (*Parser[T]) Reset

func (p *Parser[T]) Reset()

Reset resets the parser; allowing it to be reused.

func (*Parser[T]) SetTokens

func (p *Parser[T]) SetTokens(tokens []*gr.Token[T])

SetTokens sets the list of tokens.

Parameters:

  • tokens: the list of tokens.

Does nothing if the receiver is nil.

type Rule

type Rule[T gr.TokenTyper] struct {
	// contains filtered or unexported fields
}

A rule is a production of a grammar.

func NewRule

func NewRule[T gr.TokenTyper](lhs T, rhss ...T) (*Rule[T], error)

NewRule creates a new rule.

Parameters:

  • lhs: the left hand side of the rule.
  • rhss: the right hand sides of the rule.

Returns:

  • *Rule: the new rule.
  • error: if the rule does not have at least one right hand side.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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