Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 ---^
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.
type EndOfLine ¶
type EndOfLine struct{}
EndOfLine matches the end of a line.
type Ignore ¶ added in v0.1.1
type Ignore struct {
Value any
}
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.
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.
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) String ¶
func (zero ZeroOrMore) String() string
Click to show internal directories.
Click to hide internal directories.