Documentation
¶
Overview ¶
Example (Custom) ¶
package main
import (
"fmt"
"github.com/0x51-dev/upeg/abnf/gen"
)
func main() {
g := gen.Generator{
PackageName: "custom",
CustomOperators: map[string]struct{}{
"custom": {},
"alpha": {},
"alphaNum": {},
"HEXDIG": {},
},
}
raw, _ := g.GenerateOperators([]rune("grammar = alpha alphaNum HEXDIG\ncustom = alpha\n"))
fmt.Println(raw)
}
Output: // Package custom is autogenerated by https://github.com/0x51-dev/upeg. DO NOT EDIT. package custom import ( "github.com/0x51-dev/upeg/parser/op" ) var ( Grammar = op.Capture{Name: "Grammar", Value: op.And{AlphaOperator{}, AlphaNumOperator{}, HEXDIGOperator{}}} Custom = CustomOperator{} // op.Capture{Name: "Custom", Value: AlphaOperator{}} )
Example (ExternalDependencies) ¶
package main
import (
"fmt"
"github.com/0x51-dev/upeg/abnf/gen"
)
func main() {
g := gen.Generator{
PackageName: "external",
ExternalDependencies: map[string]gen.ExternalDependency{
"alpha": {
Name: "a",
Path: "example.com/a",
},
"alphaNum": {
Name: "an",
Path: "example.com/an",
},
"HEXDIG": {
Name: "hd",
Path: "example.com/hd",
},
},
}
raw, _ := g.GenerateOperators([]rune("grammar = alpha alphaNum HEXDIG\n"))
fmt.Println(raw)
}
Output: // Package external is autogenerated by https://github.com/0x51-dev/upeg. DO NOT EDIT. package external import ( "example.com/a" "example.com/an" "example.com/hd" "github.com/0x51-dev/upeg/parser/op" ) var ( Grammar = op.Capture{Name: "Grammar", Value: op.And{a.Alpha, an.AlphaNum, hd.HEXDIG}} )
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DependencyTree ¶
type ExternalDependency ¶
type Generator ¶
type Generator struct {
PackageName string
IgnoreAll bool
Ignore map[string]struct{}
ImportCore bool
CustomOperators map[string]struct{}
ExternalDependencies map[string]ExternalDependency
// contains filtered or unexported fields
}
Example (EscapeString) ¶
package main
import (
"fmt"
"github.com/0x51-dev/upeg/abnf/gen"
)
func main() {
g := gen.Generator{
PackageName: "esc",
}
raw, _ := g.GenerateOperators([]rune("grammar = \"\\u\"\n"))
fmt.Println(raw)
}
Output: // Package esc is autogenerated by https://github.com/0x51-dev/upeg. DO NOT EDIT. package esc import ( "github.com/0x51-dev/upeg/parser/op" ) var ( Grammar = op.Capture{Name: "Grammar", Value: "\\u"} )
Example (HexConcat) ¶
package main
import (
"fmt"
"github.com/0x51-dev/upeg/abnf/gen"
)
func main() {
g := gen.Generator{
PackageName: "hexc",
}
raw, _ := g.GenerateOperators([]rune("grammar = %x74.72.75.65\n"))
fmt.Println(raw)
}
Output: // Package hexc is autogenerated by https://github.com/0x51-dev/upeg. DO NOT EDIT. package hexc import ( "github.com/0x51-dev/upeg/parser/op" ) var ( Grammar = op.Capture{Name: "Grammar", Value: op.And{rune(0x74), rune(0x72), rune(0x75), rune(0x65)}} )
Click to show internal directories.
Click to hide internal directories.