peg

package
v0.0.0-...-110beca Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2014 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Language

type Language struct {
	// contains filtered or unexported fields
}

Language defines lexing and parsing capabilities for a peg defined language.

func NewParser

func NewParser(input io.Reader) (*Language, error)

func (*Language) Parse

func (l *Language) Parse(source io.Reader) (*ParseTree, error)

Parse attemps to turn the input reader into a valid parse tree.

func (*Language) ParseString

func (l *Language) ParseString(source string) (*ParseTree, error)

ParseString is identical to Parse, but operates on string input.

type Lexeme

type Lexeme struct {
	Name         string
	Dependencies []*Lexeme

	// Lexer returns the parse tree, an error and the number of input bytes consumed.
	Lexer func(*Source, int) (*ParseTree, error, int)
	// contains filtered or unexported fields
}

func NewAlternateLexer

func NewAlternateLexer(name string, lhs, rhs *Lexeme) *Lexeme

func NewConcatLexer

func NewConcatLexer(name string, deps []*Lexeme) *Lexeme

func NewDiscardLexer

func NewDiscardLexer(lex *Lexeme) *Lexeme

func NewLiteralLexer

func NewLiteralLexer(typ, valid string) *Lexeme

func NewOptionClosure

func NewOptionClosure(lex *Lexeme) *Lexeme

func NewPlusClosure

func NewPlusClosure(lex *Lexeme) *Lexeme

func NewRegexpLexer

func NewRegexpLexer(typ string, valid *regexp.Regexp) *Lexeme

func NewRuleLexer

func NewRuleLexer(rule string) *Lexeme

func NewStarClosure

func NewStarClosure(lex *Lexeme) *Lexeme

func (*Lexeme) String

func (l *Lexeme) String() string

type ParseTree

type ParseTree struct {
	Type     string
	Data     []byte
	Children []*ParseTree
}

func (*ParseTree) String

func (p *ParseTree) String() string

type Source

type Source struct {
	// contains filtered or unexported fields
}

func NewSource

func NewSource(in io.Reader) (*Source, error)

func (*Source) Consume

func (s *Source) Consume(regex *regexp.Regexp, pos int) []byte

Consume tries to consume text matching the specified regex starting at the current position. Returns the consumed text, or nil if there was no match.

func (*Source) ConsumeLiteral

func (s *Source) ConsumeLiteral(valid []byte, pos int) []byte

Consume literal attempts to consume a literal string. Returns the consumed text, or nil if there was no match.

Jump to

Keyboard shortcuts

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