Documentation
¶
Index ¶
- func FormatError(query string, err error) string
- func IsValidField(field string) bool
- func IsValidType(typeValue string) bool
- func ParseQuery(query string) (store.Predicate, error)
- func SuggestCorrection(query string, err error) string
- func ValidateQuery(query string) error
- type BinaryExpression
- type Compiler
- type Expression
- type FieldExpression
- type Lexer
- type Node
- type Parser
- type QueryInfo
- type TextExpression
- type Token
- type TokenType
- type UnaryExpression
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatError ¶
FormatError formats a parsing or compilation error with context
func IsValidField ¶
IsValidField checks if a field name is valid
func IsValidType ¶
IsValidType checks if a type value is valid
func ParseQuery ¶
ParseQuery parses a query string and returns a predicate
Example ¶
ExampleParseQuery demonstrates basic usage of the DSL parser
package main
import (
"fmt"
"log"
"github.com/go-go-golems/glazed/pkg/help/dsl"
)
func main() {
// Simple field query
predicate, err := dsl.ParseQuery("type:example")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Parsed: type:example\n")
_ = predicate
// Boolean operations
predicate, err = dsl.ParseQuery("examples AND topic:database")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Parsed: examples AND topic:database\n")
_ = predicate
// Complex query with grouping
predicate, err = dsl.ParseQuery("(examples OR tutorials) AND topic:database")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Parsed: (examples OR tutorials) AND topic:database\n")
_ = predicate
// Text search
predicate, err = dsl.ParseQuery("\"full text search\"")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Parsed: \"full text search\"\n")
_ = predicate
}
Output: Parsed: type:example Parsed: examples AND topic:database Parsed: (examples OR tutorials) AND topic:database Parsed: "full text search"
func SuggestCorrection ¶
SuggestCorrection suggests corrections for common mistakes
func ValidateQuery ¶
ValidateQuery validates a query string without executing it
Types ¶
type BinaryExpression ¶
type BinaryExpression struct {
Left Expression
Operator string
Right Expression
}
BinaryExpression represents a binary operation (AND, OR)
func (*BinaryExpression) String ¶
func (be *BinaryExpression) String() string
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler compiles AST expressions to predicates
func (*Compiler) Compile ¶
func (c *Compiler) Compile(expr Expression) (store.Predicate, error)
Compile compiles an AST expression to a predicate
func (*Compiler) GetValidFields ¶
GetValidFields returns all valid field names
func (*Compiler) GetValidTypeValues ¶
GetValidTypeValues returns valid values for the type field
func (*Compiler) ValidateField ¶
ValidateField validates if a field name is supported
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
Expression represents an expression node
func Parse ¶
func Parse(input string) (Expression, error)
Parse parses the input and returns the AST
type FieldExpression ¶
FieldExpression represents a field:value expression
func (*FieldExpression) String ¶
func (fe *FieldExpression) String() string
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes input text
func (*Lexer) CurrentPosition ¶
CurrentPosition returns current position information
func (*Lexer) GetAllTokens ¶
GetAllTokens returns all tokens from the input (useful for testing)
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses tokens into an AST
func (*Parser) ParseExpression ¶
func (p *Parser) ParseExpression() Expression
ParseExpression parses the entire expression
type QueryInfo ¶
QueryInfo provides information about query syntax
func GetQueryInfo ¶
func GetQueryInfo() *QueryInfo
GetQueryInfo returns information about the query DSL
Example ¶
ExampleGetQueryInfo demonstrates getting information about the DSL
package main
import (
"fmt"
"github.com/go-go-golems/glazed/pkg/help/dsl"
)
func main() {
info := dsl.GetQueryInfo()
fmt.Printf("Valid fields count: %d\n", len(info.ValidFields))
fmt.Printf("Valid types: %v\n", info.ValidTypes)
fmt.Printf("Example queries: %v\n", info.Examples[:3]) // Show first 3 examples
}
Output: Valid fields count: 8 Valid types: [example tutorial topic application] Example queries: [type:example topic:database flag:--output]
type TextExpression ¶
type TextExpression struct {
Text string
}
TextExpression represents a quoted text search
func (*TextExpression) String ¶
func (te *TextExpression) String() string
type TokenType ¶
type TokenType int
TokenType represents the type of a token
const ( // Special tokens TokenIllegal TokenType = iota TokenEOF TokenError // Literals TokenIdent // identifiers like field names, values TokenString // quoted strings like "hello world" TokenFieldName // field names before colon // Operators TokenColon // : TokenAnd // AND TokenOr // OR TokenNot // NOT TokenLeftParen // ( TokenRightParen // ) )
type UnaryExpression ¶
type UnaryExpression struct {
Operator string
Right Expression
}
UnaryExpression represents a unary operation (NOT)
func (*UnaryExpression) String ¶
func (ue *UnaryExpression) String() string