visitor

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package visitor provides AST visitor implementations for validating and inspecting Cypher query syntax trees.

It includes:

  • Function validation
  • AST printing/debugging
  • Custom visitor support

Example:

validator := visitor.NewValidator()
ast.Walk(validator, query)
if validator.HasErrors() {
    for _, err := range validator.Errors() {
        log.Println(err)
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(node ast.Node) string

Print prints the AST structure of a node.

Parameters:

  • node: The AST node to print

Returns the formatted AST string.

Example:

fmt.Println(visitor.Print(query))

func RegisterFunction

func RegisterFunction(info FunctionInfo)

RegisterFunction registers a function in the global registry.

Parameters:

  • info: The function information to register

Example:

visitor.RegisterFunction(visitor.FunctionInfo{
    Name: "CUSTOM", Category: visitor.FunctionMath, MinArgs: 1, MaxArgs: 1,
})

Types

type FunctionCategory

type FunctionCategory int

FunctionCategory represents the category of a Cypher function.

const (
	FunctionAggregate FunctionCategory = iota
	FunctionList
	FunctionString
	FunctionMath
	FunctionTemporal
	FunctionCoalesce
	FunctionPath
)

Function category constants.

type FunctionInfo

type FunctionInfo struct {
	Name     string           // Function name
	Category FunctionCategory // Function category
	MinArgs  int              // Minimum number of arguments (-1 for unlimited)
	MaxArgs  int              // Maximum number of arguments (-1 for unlimited)
}

FunctionInfo contains metadata about a Cypher function.

type FunctionRegistry

type FunctionRegistry interface {
	// IsValid returns true if the function name is valid.
	IsValid(name string) bool

	// GetInfo returns function information for the given name.
	GetInfo(name string) *FunctionInfo

	// Register registers a new function.
	Register(info FunctionInfo)
}

FunctionRegistry provides an interface for function registration and lookup.

func GlobalRegistry

func GlobalRegistry() FunctionRegistry

GlobalRegistry returns the global function registry.

Returns the global FunctionRegistry instance.

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer prints the AST structure for debugging.

func NewPrinter

func NewPrinter() *Printer

NewPrinter creates a new AST printer.

Returns a new Printer instance.

Example:

printer := visitor.NewPrinter()
ast.Walk(printer, query)
fmt.Println(printer.String())

func (*Printer) String

func (p *Printer) String() string

String returns the printed AST as a string.

Returns the formatted AST string.

func (*Printer) Visit

func (p *Printer) Visit(node ast.Node) (ast.Visitor, error)

Visit implements the ast.Visitor interface. It prints the node and returns the visitor for child nodes.

Parameters:

  • node: The AST node to visit

Returns the visitor for child nodes and any error encountered.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates AST nodes for semantic correctness.

func NewValidator

func NewValidator(opts ...ValidatorOption) *Validator

NewValidator creates a new AST validator.

Parameters:

  • opts: Optional configuration options

Returns a new Validator instance.

Example:

validator := visitor.NewValidator()
ast.Walk(validator, query)

func (*Validator) Errors

func (v *Validator) Errors() []error

Errors returns all validation errors.

Returns the slice of errors.

func (*Validator) HasErrors

func (v *Validator) HasErrors() bool

HasErrors returns true if any validation errors were found.

Returns true if there are errors.

func (*Validator) Visit

func (v *Validator) Visit(node ast.Node) (ast.Visitor, error)

Visit implements the ast.Visitor interface. It validates the given node and returns the visitor for child nodes.

Parameters:

  • node: The AST node to visit

Returns the visitor for child nodes and any error encountered.

type ValidatorOption

type ValidatorOption func(*Validator)

ValidatorOption configures the Validator.

func WithRegistry

func WithRegistry(r FunctionRegistry) ValidatorOption

WithRegistry sets a custom function registry.

Parameters:

  • r: The function registry to use

Returns a ValidatorOption.

Jump to

Keyboard shortcuts

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