op

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 18

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringAny

func StringAny(v any) string

Types

type And

type And []any

And is a sequence of rules that must all match.

func (And) Match

func (and And) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (And) Parse

func (and And) Parse(p *parser.Parser) (*parser.Node, error)

func (And) String

func (and And) String() string

type Any

type Any struct{}

Any matches any character.

Example
package main

import (
	"fmt"
	"github.com/0x51-dev/upeg/parser"
	"github.com/0x51-dev/upeg/parser/op"
)

func main() {
	p, _ := parser.New([]rune("abc"))
	_, err := p.Match(op.Repeat{Min: 4, Max: 4, Value: op.Any{}})
	fmt.Println(err)
}
Output:

[1:4/1:4] '�' | no match: .
abc
---^

func (Any) Match

func (a Any) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Any) String

func (a Any) String() string

type AnyBut

type AnyBut struct {
	Value any
}

func (AnyBut) Match

func (a AnyBut) Match(_ parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (AnyBut) String

func (a AnyBut) String() string

type Capture

type Capture struct {
	// Name is required, it will otherwise be ignored while flattening the AST.
	Name string
	// Value is the expression to capture.
	Value any
}

Capture is a named expression.

func (Capture) Match

func (c Capture) Match(_ parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Capture) Parse

func (c Capture) Parse(p *parser.Parser) (*parser.Node, error)

func (Capture) String

func (c Capture) String() string

type EOF

type EOF struct{}

EOF matches the end of the input.

func (EOF) Match

func (eof EOF) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (EOF) String

func (eof EOF) String() string

type EndOfLine

type EndOfLine struct{}

EndOfLine matches the end of a line.

func (EndOfLine) Match

func (e EndOfLine) Match(_ parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (EndOfLine) String

func (e EndOfLine) String() string

type Ignore added in v0.1.1

type Ignore struct {
	Value any
}

func (Ignore) Match added in v0.1.1

func (s Ignore) Match(_ parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Ignore) String added in v0.1.1

func (s Ignore) String() string

type Not

type Not struct {
	Value any
}

Not matches if the given expression does not match.

func (Not) Match

func (n Not) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Not) String

func (n Not) String() string

type OneOrMore

type OneOrMore struct {
	Value any
}

func (OneOrMore) Match

func (one OneOrMore) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (OneOrMore) Parse

func (one OneOrMore) Parse(p *parser.Parser) (*parser.Node, error)

func (OneOrMore) String

func (one OneOrMore) String() string

type OperatorType

type OperatorType int
const (
	UndefinedType OperatorType = iota
	AndType
	AnyType
	CaptureType
	EOLType
	NotType
	OneOrMoreType
	OptionalType
	OrType
	RuneRangeType
	SpaceType
	ZeroOrMoreType
)

type Optional

type Optional struct {
	Value any
}

Optional matches the given value or nothing.

func (Optional) Match

func (o Optional) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Optional) Parse

func (o Optional) Parse(p *parser.Parser) (*parser.Node, error)

func (Optional) String

func (o Optional) String() string

type Or

type Or []any

func (Or) Match

func (or Or) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Or) Parse

func (or Or) Parse(p *parser.Parser) (*parser.Node, error)

func (Or) String

func (or Or) String() string

type Peek

type Peek struct {
	Value any
}

func (Peek) Match

func (n Peek) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Peek) String

func (n Peek) String() string

type Reference

type Reference struct {
	Name string
}

func (Reference) Match

func (r Reference) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Reference) Parse

func (r Reference) Parse(p *parser.Parser) (*parser.Node, error)

func (Reference) String

func (r Reference) String() string

type Repeat

type Repeat struct {
	Min   uint
	Max   int
	Value any
}

func (Repeat) Match

func (r Repeat) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Repeat) Parse

func (r Repeat) Parse(p *parser.Parser) (*parser.Node, error)

func (Repeat) String

func (r Repeat) String() string

type RuneRange

type RuneRange struct {
	// Min is the minimum rune in the range.
	Min rune
	// Max is the maximum rune in the range.
	Max rune
}

RuneRange matches a range of runes, inclusive.

func (RuneRange) Match

func (r RuneRange) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (RuneRange) String

func (r RuneRange) String() string

type Space

type Space struct{}

Space matches a space character, a tab character or a line break.

func (Space) Match

func (s Space) Match(_ parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (Space) String

func (s Space) String() string

type ZeroOrMore

type ZeroOrMore struct {
	Value any
}

ZeroOrMore matches the given expression zero or more times.

Example (EndsWith)
package main

import (
	"fmt"
	"github.com/0x51-dev/upeg/parser"
	"github.com/0x51-dev/upeg/parser/op"
)

func main() {
	p, _ := parser.New([]rune("aa.a.a.a"))
	start := p.Reader.Cursor()
	c, err := p.Match(op.And{op.ZeroOrMore{Value: op.And{
		op.Or{'a', '.'},
		op.Peek{Value: op.Or{'a', '.'}},
	}}, 'a'})
	fmt.Println(string(p.Reader.GetInputRange(start, c)), err)
}
Output:

aa.a.a.a <nil>

func (ZeroOrMore) Match

func (zero ZeroOrMore) Match(start parser.Cursor, p *parser.Parser) (parser.Cursor, error)

func (ZeroOrMore) Parse

func (zero ZeroOrMore) Parse(p *parser.Parser) (*parser.Node, error)

func (ZeroOrMore) String

func (zero ZeroOrMore) String() string

Jump to

Keyboard shortcuts

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