internal

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var QueryConstNameRegex *regexp.Regexp = func() *regexp.Regexp {
	return regexp.MustCompile(".*Query(Fragment)?[_0-9]*$")
}()
View Source
var SubstitutionRegex *regexp.Regexp = func() *regexp.Regexp {
	rawIdentifier := `[a-zA-Z_][a-zA-Z0-9_]*`

	typeName := fmt.Sprintf(`(\*?%s\.)?[a-zA-Z0-9_*\[\] ]+`, rawIdentifier)
	return regexp.MustCompile(fmt.Sprintf(
		`{{\s*(%s)\s*:\s*(%s)\s*(:\s*(%%(.+?))\s*)?}}`, rawIdentifier, typeName))
}()

SubstitutionRegex represents interpolation syntax. Conceptually, the following syntaxes are allowed

{{ fieldName : typeName }}
{{ fieldName : _ }} // allowed for 2nd, 3rd etc. interpolation of same field

formatSpec must not contain positional arguments (i.e. %[0]f is not OK)

Functions

func WriteStructs

func WriteStructs(wanted []GoStruct, buf *bytes.Buffer, shouldImportInterpolate bool)

Types

type Def

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

type GoStruct

type GoStruct struct {
	TypeName string
	Fields   []GoStructField
}

type GoStructField

type GoStructField struct {
	Name    string
	Type    TypeName
	Indexes []int
}

type GoStructFieldBuilder

type GoStructFieldBuilder struct {
	Name     string
	TypeName string
	Index    int
}

GoStructFieldBuilder maps N-1 to GoStructField, as the same field may be interpolated multiple times in the same query.

func NewFieldBuilder

func NewFieldBuilder(matchIndex int, matches []string) GoStructFieldBuilder

type PosToDefMap

type PosToDefMap map[token.Pos]Def

type QueryGenVisitor

type QueryGenVisitor struct {

	// ParamStructs is the list of GoStructs generated for a file.
	ParamStructs []GoStruct
	// contains filtered or unexported fields
}

func NewQueryGenVisitor

func NewQueryGenVisitor(logger *log.Logger, pass *analysis.Pass) *QueryGenVisitor

func (*QueryGenVisitor) Visit

func (q *QueryGenVisitor) Visit(node ast.Node) ast.Visitor

type Set

type Set[T comparable] map[T]struct{}

func (Set[T]) Add

func (s Set[T]) Add(t T)

func (Set[T]) Has

func (s Set[T]) Has(t T) bool

func (Set[T]) Remove

func (s Set[T]) Remove(t T)

type StructFactory

type StructFactory struct {
	Pass *analysis.Pass
}

func (*StructFactory) NewGoStruct

func (factory *StructFactory) NewGoStruct(subregex *regexp.Regexp, queryConst *ast.Ident, templateText string) (*GoStruct, error)

NewGoStruct attempts to build a GoStruct from the given query string.

There are 3 outcomes: 1. If the query was using string interpolation and is well-formed: returns a GoStruct 2. If the query was using string interpolation and is ill-formed: returns nil, err 3. If the query was not using string interpolation: returns nil, nil

type TypeName

type TypeName struct {
	Name string
}

Jump to

Keyboard shortcuts

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