lrparser

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: AGPL-3.0 Imports: 4 Imported by: 2

README

lrparser

An LR parser

Documentation

Overview

Package lrparser is an LR-parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoalesceSymbols

func CoalesceSymbols(tokens []*textkit.Token, clusters []string) []*textkit.Token

CoalesceSymbols joins symbols together.

Types

type Grammar

type Grammar struct {
	// The rules of the grammar.
	Rules []*Rule
	// contains filtered or unexported fields
}

Grammar is a formal grammar.

func NewGrammar

func NewGrammar(rules ...[]*Rule) *Grammar

NewGrammar returns a new grammar.

func (*Grammar) BuildItems

func (gr *Grammar) BuildItems()

BuildItems builds the items of the automaton.

func (*Grammar) Parse

func (gr *Grammar) Parse(tokens []*textkit.Token) (interface{}, error)

Parse parses a list of tokens.

type Item

type Item struct {
	LHS    string
	RHS    []string
	DotPos int
}

Item is an item of the parser.

func (*Item) String

func (it *Item) String() string

type Located added in v0.1.4

type Located interface {
	Location() textkit.Location
	SetLocation(textkit.Location)
}

Located specifies methods for AST node location.

type Operator

type Operator struct {
	Associativity OperatorAssociativity
	Priority      int
	Symbols       []string
}

Operator ...

func (Operator) Name

func (op Operator) Name() string

Name returns the operator's name.

type OperatorAssociativity

type OperatorAssociativity int

OperatorAssociativity ...

const (
	LeftAssociative OperatorAssociativity = iota
	RightAssociative
	NonAssociative
)

constants for OperatorAssociativity

type Rule

type Rule struct {
	LHS  string
	RHS  []string
	Conv func([]interface{}) interface{}
}

Rule is a context-free rule with a builder function.

func BuildListRules

func BuildListRules(root, leaf string, canBeEmpty bool, leftBracket, sep, rightBracket string, builder func([]interface{}) interface{}) []*Rule

BuildListRules builds list rules.

func BuildOperatorRules

func BuildOperatorRules(root, leaf string, ops []Operator, builder func(string, interface{}, interface{}) interface{}) []*Rule

BuildOperatorRules builds operator rules.

func BuildOptSeq

func BuildOptSeq(root string, head, tail []string, builder func([]interface{}, []interface{}) interface{}) []*Rule

BuildOptSeq builds an optional sequence.

func (*Rule) String

func (r *Rule) String() string

String returns a string representation of the rule.

type State

type State struct {
	Items []*Item
}

State is a state of the parser.

func (*State) String

func (st *State) String() string

Jump to

Keyboard shortcuts

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