parser

package
v0.1.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse[K comparable, P float32 | float64](q string) (cmd CommandNode, warns []Warning, err error)

Types

type AnchorFieldNode

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

Search nodes are particular nodes using for graph and full text search (entity, topic)

func (AnchorFieldNode) Clause

func (n AnchorFieldNode) Clause() *ClauseNode

func (AnchorFieldNode) End

func (n AnchorFieldNode) End() lexer.Position

func (AnchorFieldNode) Field

func (n AnchorFieldNode) Field() FieldNode[string]

func (AnchorFieldNode) Key

func (n AnchorFieldNode) Key() string

func (AnchorFieldNode) Pos

func (n AnchorFieldNode) Pos() lexer.Position

func (AnchorFieldNode) String

func (n AnchorFieldNode) String() string

func (AnchorFieldNode) Value

func (n AnchorFieldNode) Value() string

type AstNode

type AstNode interface {
	// Text returns the original text of the element.
	String() string

	Pos() lexer.Position
	End() lexer.Position
}

type ClauseNode

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

type ClauseType

type ClauseType int
const (
	MUST     ClauseType = iota // +
	MUST_NOT                   // -
	LOOSE                      // ±
)

type CommandNode

type CommandNode interface {
	AstNode
	Selector() uint8
}

Node representing a command (remember, recall)

type DepthFieldNode

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

Depth field

func (DepthFieldNode) End

func (n DepthFieldNode) End() lexer.Position

func (DepthFieldNode) Key

func (n DepthFieldNode) Key() string

func (DepthFieldNode) Pos

func (n DepthFieldNode) Pos() lexer.Position

func (DepthFieldNode) String

func (n DepthFieldNode) String() string

func (DepthFieldNode) Value

func (n DepthFieldNode) Value() int

type EntityFieldNode

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

Entity field

func (EntityFieldNode) End

func (n EntityFieldNode) End() lexer.Position

func (EntityFieldNode) Key

func (n EntityFieldNode) Key() string

func (EntityFieldNode) Pos

func (n EntityFieldNode) Pos() lexer.Position

func (EntityFieldNode) String

func (n EntityFieldNode) String() string

func (EntityFieldNode) Value

func (n EntityFieldNode) Value() string

type Error

type Error struct {
	Msg string
	Pos lexer.Position
}

Error is a parse failure at a specific position in the query. It is returned (wrapped) by the query layer; recover it with errors.As to get the position.

func (*Error) Error

func (e *Error) Error() string

type FieldNode

type FieldNode[T any] interface {
	AstNode
	Key() string
	Value() T
}

Node representing a field (topic, since, until, )

type GraphSelectorNode

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

Selector node is the graph selection statement

func (GraphSelectorNode) End

func (GraphSelectorNode) Pos

func (GraphSelectorNode) String

func (n GraphSelectorNode) String() string

func (GraphSelectorNode) Value

func (n GraphSelectorNode) Value() uint8

type LiteralFieldNode

type LiteralFieldNode interface {
	AstNode
	Literal() string
}

literal field

type PhraseNode

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

Phrase representation. A phrase is a quoted text search

func (PhraseNode) End

func (n PhraseNode) End() lexer.Position

func (PhraseNode) Literal

func (n PhraseNode) Literal() string

Literal returns the phrase text exactly as written between the quotes, with the escape (”) already decoded and no surrounding quotes. Interior spacing is preserved verbatim — the phrase is opaque literal text.

func (PhraseNode) Pos

func (n PhraseNode) Pos() lexer.Position

func (PhraseNode) String

func (n PhraseNode) String() string

type RecallCommandNode

type RecallCommandNode[K comparable, P float32 | float64] struct {
	// contains filtered or unexported fields
}

recall command node

func (RecallCommandNode[K, P]) Depth

func (r RecallCommandNode[K, P]) Depth(v int) int

func (RecallCommandNode[K, P]) End

func (n RecallCommandNode[K, P]) End() lexer.Position

func (RecallCommandNode[K, P]) Entities

func (r RecallCommandNode[K, P]) Entities() []string

func (RecallCommandNode[K, P]) HasDepth

func (r RecallCommandNode[K, P]) HasDepth() bool

HasDepth reports whether the recall carried an explicit depth clause, as opposed to falling back to the configured default. Presence is the parsed depth key, not a nonzero value, so an explicit depth:0 is honoured as the floor lane instead of collapsing to the default.

func (RecallCommandNode[K, P]) HasTop

func (r RecallCommandNode[K, P]) HasTop() bool

HasTop reports whether the recall carried an explicit top clause, as opposed to falling back to the configured default. Presence is the parsed top key, not a nonzero value, so an explicit top:0 stays visible to the range check and is rejected as out of range instead of silently answering with the default. Ceiling checks apply only to a client-supplied value, never to the trusted default.

func (RecallCommandNode[K, P]) Pos

func (n RecallCommandNode[K, P]) Pos() lexer.Position

func (RecallCommandNode[K, P]) Selector

func (n RecallCommandNode[K, P]) Selector() uint8

func (RecallCommandNode[K, P]) Since

func (r RecallCommandNode[K, P]) Since() containers.TimeValue[K]

func (RecallCommandNode[K, P]) String

func (n RecallCommandNode[K, P]) String() string

func (RecallCommandNode[K, P]) Terms

func (r RecallCommandNode[K, P]) Terms() []string

func (RecallCommandNode[K, P]) Top

func (r RecallCommandNode[K, P]) Top(v int) int

func (RecallCommandNode[K, P]) Topics

func (r RecallCommandNode[K, P]) Topics() []string

func (RecallCommandNode[K, P]) Until

func (r RecallCommandNode[K, P]) Until() containers.TimeValue[K]

func (RecallCommandNode[K, P]) VecParam

func (r RecallCommandNode[K, P]) VecParam() (string, bool)

VecParam reports the name of the vector placeholder (the identifier after `vec:$`) and whether the recall carried one at all. The parser only records the placeholder; the real vector is bound later from the request parameters.

func (RecallCommandNode[K, P]) Vector

func (r RecallCommandNode[K, P]) Vector() []P

type RefFieldNode

type RefFieldNode[T any] interface {
	AstNode
	FieldNode[T]
	Param() string
}

Ref field

type RememberCommandNode

type RememberCommandNode[P float32 | float64] struct {
	// contains filtered or unexported fields
}

remember command node

func (RememberCommandNode[P]) End

func (n RememberCommandNode[P]) End() lexer.Position

func (RememberCommandNode[P]) Entities

func (r RememberCommandNode[P]) Entities() []string

func (RememberCommandNode[P]) Pos

func (n RememberCommandNode[P]) Pos() lexer.Position

func (RememberCommandNode[P]) Selector

func (n RememberCommandNode[P]) Selector() uint8

func (RememberCommandNode[P]) String

func (n RememberCommandNode[P]) String() string

func (RememberCommandNode[P]) Topics

func (r RememberCommandNode[P]) Topics() []string

func (RememberCommandNode[P]) Value

func (r RememberCommandNode[P]) Value() string

func (RememberCommandNode[P]) VecParam

func (r RememberCommandNode[P]) VecParam() (string, bool)

func (RememberCommandNode[P]) Vector

func (r RememberCommandNode[P]) Vector() []P

type SinceFieldNode

type SinceFieldNode[K comparable] struct {
	// contains filtered or unexported fields
}

Since field

func (SinceFieldNode[K]) End

func (n SinceFieldNode[K]) End() lexer.Position

func (SinceFieldNode[K]) Key

func (n SinceFieldNode[K]) Key() string

func (SinceFieldNode[K]) Pos

func (n SinceFieldNode[K]) Pos() lexer.Position

func (SinceFieldNode[K]) String

func (n SinceFieldNode[K]) String() string

func (SinceFieldNode[K]) TimeValue

func (n SinceFieldNode[K]) TimeValue() time.Time

func (SinceFieldNode[K]) Value

func (n SinceFieldNode[K]) Value() containers.TimeValue[K]

type TermNode

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

a term is a search keyword or phrase. A query supports multiple terms or one phrase

func (TermNode) End

func (n TermNode) End() lexer.Position

func (TermNode) Literal

func (n TermNode) Literal() string

Literal returns the term as the parser interpreted it: folded to lower case. The token keeps the source spelling for positions and error text; matching and cache keys must see only this folded form, or one search would exist under as many plan-cache entries as it has capitalisations.

func (TermNode) Pos

func (n TermNode) Pos() lexer.Position

func (TermNode) String

func (n TermNode) String() string

type Terms

type Terms []TermNode

makes it easier to manage a list of TermNode

func (Terms) End

func (n Terms) End() lexer.Position

func (Terms) Literal

func (n Terms) Literal() string

func (Terms) Pos

func (n Terms) Pos() lexer.Position

func (Terms) String

func (n Terms) String() string

type TimeValueFieldNode

type TimeValueFieldNode[K comparable] interface {
	FieldNode[containers.TimeValue[K]]
	TimeValue() time.Time
}

type TopFieldNode

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

Top field

func (TopFieldNode) End

func (n TopFieldNode) End() lexer.Position

func (TopFieldNode) Key

func (n TopFieldNode) Key() string

func (TopFieldNode) Pos

func (n TopFieldNode) Pos() lexer.Position

func (TopFieldNode) String

func (n TopFieldNode) String() string

func (TopFieldNode) Value

func (n TopFieldNode) Value() int

type TopicFieldNode

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

Topic field

func (TopicFieldNode) End

func (n TopicFieldNode) End() lexer.Position

func (TopicFieldNode) Key

func (n TopicFieldNode) Key() string

func (TopicFieldNode) Pos

func (n TopicFieldNode) Pos() lexer.Position

func (TopicFieldNode) String

func (n TopicFieldNode) String() string

func (TopicFieldNode) Value

func (n TopicFieldNode) Value() string

type UntilFieldNode

type UntilFieldNode[K comparable] struct {
	// contains filtered or unexported fields
}

Until field

func (UntilFieldNode[K]) End

func (n UntilFieldNode[K]) End() lexer.Position

func (UntilFieldNode[K]) Key

func (n UntilFieldNode[K]) Key() string

func (UntilFieldNode[K]) Pos

func (n UntilFieldNode[K]) Pos() lexer.Position

func (UntilFieldNode[K]) String

func (n UntilFieldNode[K]) String() string

func (UntilFieldNode[K]) TimeValue

func (n UntilFieldNode[K]) TimeValue() time.Time

func (UntilFieldNode[K]) Value

func (n UntilFieldNode[K]) Value() containers.TimeValue[K]

type VecFieldNode

type VecFieldNode[P float32 | float64] struct {
	// contains filtered or unexported fields
}

Ref field

func (VecFieldNode[P]) End

func (n VecFieldNode[P]) End() lexer.Position

func (VecFieldNode[P]) Key

func (n VecFieldNode[P]) Key() string

func (VecFieldNode[P]) Param

func (n VecFieldNode[P]) Param() string

func (VecFieldNode[P]) Pos

func (n VecFieldNode[P]) Pos() lexer.Position

func (VecFieldNode[P]) String

func (n VecFieldNode[P]) String() string

func (VecFieldNode[P]) Value

func (n VecFieldNode[P]) Value() []P

type Warning

type Warning struct {
	Msg string
	Pos lexer.Position
}

Warning is a parse-time observation about a query that ran anyway: the query is valid, but it is close enough to a different, also-valid query that a typo would change its meaning with no error to correct from. It rides the return path, never the query object — the plan cache substitutes query objects on a hash hit, so anything attached there would leak between requests.

func (Warning) String

func (w Warning) String() string

String renders the warning as clients receive it, mirroring Error's "parse error at column N" shape so a position reads the same either way.

Jump to

Keyboard shortcuts

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