shred

package module
v0.0.0-...-507a558 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: LGPL-2.1 Imports: 7 Imported by: 0

README

shred

A shift-reduce parser in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EOF

type EOF struct{}

An EOF terminal.

func (EOF) Kind

func (s EOF) Kind() Kind

func (EOF) String

func (s EOF) String() string

type Grammar

type Grammar struct {
	Rules []*Rule
	// contains filtered or unexported fields
}

An attribute LR-grammar.

func NewGrammar

func NewGrammar(rules []*Rule) *Grammar

NewGrammar creates a new grammar with the given rules.

func (*Grammar) Build

func (gr *Grammar) Build() error

Build builds an automaton for the grammar.

func (*Grammar) Parse

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

Parse parses a sequence of tokens.

type Ident

type Ident struct{}

An identifier terminal.

func (Ident) Kind

func (s Ident) Kind() Kind

func (Ident) String

func (s Ident) String() string

type Kind

type Kind byte

Kind is a token's type.

const (
	KindIdent Kind = iota
	KindInt
	KindFloat
	KindString
	KindRawString
	KindChar
	KindEOF
	KindOther
	KindMatch
)

type Match

type Match struct {
	Text string
}

A match terminal.

func (Match) Kind

func (s Match) Kind() Kind

func (Match) String

func (s Match) String() string

type NonTerminal

type NonTerminal struct {
	Name string
}

NonTerminal is a non-terminal symbol.

func (NonTerminal) String

func (s NonTerminal) String() string

String returns the name of the non-terminal.

type Rule

type Rule struct {
	Lhs     string
	Rhs     []Symbol
	Builder func([]interface{}) interface{}
}

A context-free rule with an assiciated AST builder.

func (*Rule) String

func (r *Rule) String() string

type Symbol

type Symbol interface {
	fmt.Stringer
}

Symbol is a terminal or non-terminal.

type Terminal

type Terminal interface {
	Symbol
	Kind() Kind
}

Terminal is a terminal symbol.

type Token

type Token interface {
	fmt.Stringer
	Text() string
	Kind() Kind
	IsEOF() bool
	IsIdent() bool
	IsInt() bool
	IsFloat() bool
	IsString() bool
	IsRawString() bool
	IsChar() bool
	Line() int
	Column() int
}

Token is a text token.

func Tokenise

func Tokenise(r io.Reader) []Token

Tokenise tokenises the contents of a reader.

func TokeniseString

func TokeniseString(s string) []Token

TokeniseString tokenises a string.

Jump to

Keyboard shortcuts

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