peg

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 1 Imported by: 0

README

go-peg

PEG(Parsing Expression Grammar) parser combinator for Go.

Features

  • Packrat parsing
  • Longest match
  • Direct and indirect left-recursive grammar rules

License

This software is released under the MIT License, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EOT = NewNot(Any)

Functions

This section is empty.

Types

type And

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

func NewAnd

func NewAnd(expr Expr) *And

func (*And) Parse

func (a *And) Parse(scan *Scanner) (*Tree, bool)

type Charclass

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

func NewCharclass

func NewCharclass(set RuneSubset) *Charclass

func (*Charclass) Parse

func (c *Charclass) Parse(scan *Scanner) (*Tree, bool)

type Choice

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

func NewChoice

func NewChoice(exprs ...Expr) *Choice

func (*Choice) Parse

func (c *Choice) Parse(scan *Scanner) (*Tree, bool)

type Expr

type Expr interface {
	Parse(s *Scanner) (*Tree, bool)
}

type Limit

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

func NewLimit

func NewLimit(lower, upper int) *Limit

func NewLimitLower

func NewLimitLower(lower int) *Limit

func NewLimitUpper

func NewLimitUpper(upper int) *Limit

func (*Limit) Over

func (l *Limit) Over(val int) bool

func (*Limit) Under

func (l *Limit) Under(val int) bool

type Literal

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

func NewLiteral

func NewLiteral(text string) *Literal

func (*Literal) Parse

func (l *Literal) Parse(scan *Scanner) (*Tree, bool)

type Memo

type Memo struct {
	Pos  int
	Tree *Tree
}

type Not

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

func NewNot

func NewNot(expr Expr) *Not

func (*Not) Parse

func (n *Not) Parse(scan *Scanner) (*Tree, bool)

type Optional

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

func NewOptional

func NewOptional(expr Expr) *Optional

func (*Optional) Parse

func (o *Optional) Parse(scan *Scanner) (*Tree, bool)

type Repeat

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

func NewOneOrMore

func NewOneOrMore(expr Expr) *Repeat

func NewRepeat

func NewRepeat(expr Expr, limit *Limit) *Repeat

func NewZeroOrMore

func NewZeroOrMore(expr Expr) *Repeat

func (*Repeat) Parse

func (r *Repeat) Parse(scan *Scanner) (*Tree, bool)

type Rule

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

func NewRule

func NewRule(name string) *Rule

func (*Rule) Define

func (r *Rule) Define(expr Expr)

func (*Rule) Parse

func (r *Rule) Parse(scan *Scanner) (*Tree, bool)

type RuneAny

type RuneAny struct{}

func (RuneAny) Within

func (RuneAny) Within(x rune) bool

type RuneInvert

type RuneInvert struct {
	S RuneSubset
}

^A

func (RuneInvert) Within

func (i RuneInvert) Within(x rune) bool

type RuneRange

type RuneRange [2]rune

LowerBound - UpperBound

func (RuneRange) Within

func (r RuneRange) Within(x rune) bool

type RuneSubset

type RuneSubset interface {
	Within(rune) bool
}

type RuneUnion

type RuneUnion []RuneSubset

A B C ...

func (RuneUnion) Within

func (u RuneUnion) Within(x rune) bool

type RuneValue

type RuneValue rune

func (RuneValue) Within

func (v RuneValue) Within(x rune) bool

type Scanner

type Scanner struct {
	Text string
	Pos  int
	LPos int
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(text string) *Scanner

func (*Scanner) Longest

func (s *Scanner) Longest() string

func (*Scanner) Memo

func (s *Scanner) Memo(pos int, name string) (Memo, bool)

func (*Scanner) SetMemo

func (s *Scanner) SetMemo(pos int, name string, memo Memo)

type Sequence

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

func NewSequence

func NewSequence(exprs ...Expr) *Sequence

func (*Sequence) Parse

func (s *Sequence) Parse(scan *Scanner) (*Tree, bool)

type Tag

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

func NewTag

func NewTag(name string, expr Expr) *Tag

func (*Tag) Parse

func (t *Tag) Parse(scan *Scanner) (*Tree, bool)

type Tree

type Tree struct {
	Start int
	End   int
	Child []*Tree
	Tags  map[string]struct{}
	Index int
}

func NewTree

func NewTree(pos int) *Tree

func (*Tree) Append

func (t *Tree) Append(c *Tree)

func (*Tree) SetTag

func (t *Tree) SetTag(name string)

Directories

Path Synopsis
cmd
gen
examples

Jump to

Keyboard shortcuts

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