antlrhelpers

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNullable

func AllNullable(fs ...func() bool) func() bool

func AnyNullable

func AnyNullable(fs ...func() bool) func() bool

func ExpandQuotedSource

func ExpandQuotedSource(buf *strings.Builder, source QuerySource)

func NeverNullable

func NeverNullable(...func() bool) func() bool

func NotNullable

func NotNullable() bool

func Nullable

func Nullable() bool

Types

type Function

type Function struct {
	RequiredArgs         int
	Variadic             bool
	Args                 []string
	ReturnType           string
	CalcReturnType       func(...string) string // If present, will be used to calculate the return type
	ShouldArgsBeNullable bool
	CalcNullable         func(...func() bool) func() bool // will be provided with the nullability of the args
}

func GetFunctionType

func GetFunctionType(functions Functions, funcName string, argTypes []string) (Function, error)

func (Function) ArgType

func (f Function) ArgType(i int) string

type Functions

type Functions map[string]Function

type Node

type Node interface {
	GetStart() antlr.Token
	GetStop() antlr.Token
	GetText() string
	GetParser() antlr.Parser
}

type NodeInfo

type NodeInfo struct {
	Node                 Node
	ExprDescription      string
	Type                 NodeTypes
	ExprRef              Node
	IgnoreRefNullability bool

	// Go Info
	ArgKey         string // Positional or named arg in the query
	EditedPosition [2]int
	CanBeMultiple  bool
}

type NodeKey

type NodeKey struct {
	Start int
	Stop  int
}

func Key

func Key(ctx Node) NodeKey

type NodeType

type NodeType struct {
	DBType    string
	NullableF func() bool
}

func GetColumnType

func GetColumnType[C, I any](db drivers.Tables[C, I], schema, table, column string) NodeType

func KnownType

func KnownType(t string, nullable func() bool) NodeType

func KnownTypeNotNull

func KnownTypeNotNull(t string) NodeType

func KnownTypeNull

func KnownTypeNull(t string) NodeType

func (NodeType) Nullable

func (e NodeType) Nullable() bool

func (NodeType) String

func (e NodeType) String() string

type NodeTypes

type NodeTypes []NodeType

func GetDBType

func GetDBType(exprs map[NodeKey]NodeInfo, e NodeInfo) NodeTypes

func (NodeTypes) ConfirmedDBType

func (e NodeTypes) ConfirmedDBType() string

func (NodeTypes) List

func (e NodeTypes) List() []string

func (NodeTypes) Match

func (existing NodeTypes) Match(newTypes NodeTypes) NodeTypes

Get the common types between the two sets of node types.

func (NodeTypes) Nullable

func (e NodeTypes) Nullable() bool

type QuerySource

type QuerySource struct {
	Schema  string
	Name    string
	Columns []ReturnColumn
	CTE     bool
}

type QuerySources

type QuerySources = []QuerySource

type ReturnColumn

type ReturnColumn struct {
	Name   string
	Type   NodeTypes
	Config drivers.QueryCol
}

type StmtInfo

type StmtInfo struct {
	Node      Node
	QueryType bob.QueryType
	Comment   string
	Columns   []ReturnColumn
	EditRules []internal.EditRule
	Mods      *strings.Builder
	Imports   [][]string
}

type Visitor

type Visitor[C, I any] struct {
	Err       error
	DB        drivers.Tables[C, I]
	Args      []NodeKey
	Groups    []NodeKey
	Names     map[NodeKey]string
	Infos     map[NodeKey]NodeInfo
	Sources   []QuerySource
	Functions Functions
	BaseRules []internal.EditRule

	// Refresh these for each statement
	StmtRules []internal.EditRule
	Atom      *atomic.Int64
}

func (Visitor[C, I]) GetArgs

func (v Visitor[C, I]) GetArgs(start, stop int, translate func(string) (string, []string), comment func(Node) string) []drivers.QueryArg

func (Visitor[C, I]) GetName

func (v Visitor[C, I]) GetName(expr Node) string

func (*Visitor[C, I]) MatchNames

func (w *Visitor[C, I]) MatchNames(p1, p2 NodeKey)

func (*Visitor[C, I]) MatchNodeNames

func (v *Visitor[C, I]) MatchNodeNames(p1, p2 Node)

func (*Visitor[C, I]) MaybeSetName

func (v *Visitor[C, I]) MaybeSetName(key NodeKey, name string)

func (*Visitor[C, I]) MaybeSetNodeName

func (v *Visitor[C, I]) MaybeSetNodeName(ctx Node, name string)

func (*Visitor[C, I]) SetArg

func (v *Visitor[C, I]) SetArg(expr Node)

func (*Visitor[C, I]) SetGroup

func (v *Visitor[C, I]) SetGroup(expr Node)

func (*Visitor[C, I]) UpdateInfo

func (v *Visitor[C, I]) UpdateInfo(info NodeInfo)

Jump to

Keyboard shortcuts

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