gen

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: 12 Imported by: 0

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 DependencyTree = map[string]map[string]struct{}

type ExternalDependency

type ExternalDependency struct {
	Name string
	Path string
}

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 (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)}}
)

func (*Generator) GenerateOperators

func (g *Generator) GenerateOperators(input []rune) (string, error)

Jump to

Keyboard shortcuts

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