debug

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

The debug package is great for testing and debugging of parse.Parser implementations.

Index

Constants

This section is empty.

Variables

View Source
var Input = &Debug{
	A: int64(1),
	B: []string{"b2", "b3"},
	C: &Debug{
		A: int64(2),
		D: ptr(int32(3)),
		E: []*Debug{
			{
				B: []string{"b4"},
			},
			{
				B: []string{"b5"},
			},
		},
	},
	D: ptr(int32(4)),
	F: []uint32{5},
}

Input is a sample instance of the Debug struct.

View Source
var Output = Nodes{
	Field(`A`, `1`),
	Nested(`B`,
		Field(`0`, `b2`),
		Field(`1`, `b3`),
	),
	Nested(`C`,
		Field(`A`, `2`),
		Field(`D`, `3`),
		Nested(`E`,
			Nested(`0`,
				Field(`A`, `0`),
				Nested(`B`,
					Field(`0`, `b4`),
				),
			),
			Nested(`1`,
				Field(`A`, `0`),
				Nested(`B`,
					Field(`0`, `b5`),
				),
			),
		),
	),
	Field(`D`, `4`),
	Nested(`F`,
		Field(`0`, `5`),
	),
}

Output is a sample instance of Nodes that repesents the Input variable after it has been parsed by Walk.

Functions

func NewBoolValue

func NewBoolValue(v bool) parse.Token

NewBoolValue wraps a native go type into a parse.Token.

func NewBytesValue

func NewBytesValue(v []byte) parse.Token

NewBytesValue wraps a native go type into a parse.Token.

func NewDoubleValue

func NewDoubleValue(v float64) parse.Token

NewDoubleValue wraps a native go type into a parse.Token.

func NewIntValue

func NewIntValue(v int64) parse.Token

NewIntValue wraps a native go type into a parse.Token.

func NewLogger added in v0.8.3

func NewLogger(p parse.ParserWithInit, logger Logger) parse.ParserWithInit

NewLogger returns a parser that when called returns and logs the value returned by the argument parser to the argument logger.

func NewStringValue

func NewStringValue(v string) parse.Token

NewStringValue wraps a native go type into a parse.Token.

func NewUintValue

func NewUintValue(v uint64) parse.Token

NewUintValue wraps a native go type into a parse.Token.

func RandomWalk added in v0.8.3

func RandomWalk(p parse.Parser, r Rand, next, skip int) error

RandomWalk does a random walk of the parser, given two probabilities.

The next parameter is passed to r.Intn and when a zero value is returned the Next method on the parser is called.
The skip parameter is passed to r.Intn and when a non zero value is returned the Skip method on the parser is called.

RandomWalk is great for testing that the implemented parser can handle random skipping of parts of the tree.

func Walk added in v0.8.3

func Walk(p parse.Parser) error

Walk walks through the whole parser in a top down manner.

Types

type Debug added in v0.8.3

type Debug struct {
	A int64
	B []string `json:"B,omitempty"`
	C *Debug   `json:"C,omitempty"`
	D *int32   `json:"D,omitempty"`
	E []*Debug `json:"E,omitempty"`
	F []uint32 `json:"F,omitempty"`
	G *float64 `json:"G,omitempty"`
}

type Logger added in v0.8.3

type Logger interface {
	Printf(format string, v ...any)
}

Logger is an interface for a type that is made to log debug info.

func NewDelayLogger added in v0.8.3

func NewDelayLogger(delay time.Duration) Logger

NewDelayLogger returns a logger that sleeps after every log. This is useful for debugging infinite loops.

func NewLineLogger added in v0.8.3

func NewLineLogger() Logger

NewLineLogger returns a logger that logs the line at which the Printf method was called to stderr.

type Node added in v0.8.3

type Node struct {
	Label    string
	Children Nodes
}

Node is a type that represents a node in a tree. It has a label an children nodes.

func Field added in v0.8.3

func Field(name string, value string) Node

Field is a helper function for creating a Node with a label and one child label. This is how a field with a value is typically represented.

func Nested added in v0.8.3

func Nested(name string, fs ...Node) Node

Nested is a helper function for creating a Node.

func (Node) Equal added in v0.8.3

func (n Node) Equal(m Node) bool

Equal returns whether two Nodes are the same.

func (Node) String added in v0.8.3

func (n Node) String() string

String returns a string representation of Node.

type Nodes added in v0.8.3

type Nodes []Node

Nodes is a list of Node.

func Parse added in v0.8.3

func Parse(p parse.Parser) (Nodes, error)

Parse parses through the whole parser in a top down manner and records the values into a Nodes structute.

func RandomParse added in v0.8.3

func RandomParse(p parse.Parser, r Rand, next, skip int) (Nodes, error)

RandomParse does a random parse of the parser, given two probabilities.

next is passed to r.Intn and when a non zero value is returned the Next method on the parser is called.
skip is passed to r.Intn and when a zero value is returned the Skip method on the parser is called.

RandomParse is great for testing that the implemented parser can handle random skipping of parts of the tree.

func (Nodes) Equal added in v0.8.3

func (n Nodes) Equal(m Nodes) bool

Equal returns whether two Node lists are equal.

func (Nodes) String added in v0.8.3

func (n Nodes) String() string

String returns a string representation of Nodes.

type Rand added in v0.8.3

type Rand interface {
	Intn(n int) int
}

Rand is a subset of the interface that is implemented by math/rand representing only the methods used by the RandomWalk function.

func NewRand added in v0.8.3

func NewRand() Rand

NewRand returns a random integer generator, that can be used with RandomWalk. Its seed is the current time.

Jump to

Keyboard shortcuts

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