parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEYWORD = `` /* 199-byte string literal not displayed */

	OPERATORS = `<> | != | <= | >= | == | @ | [-+*/%,.()=<>]`
	SPACE     = `\s+`
	IDENTITY  = `[a-zA-Z][a-zA-Z0-9_\.\/\-]*`
	NUMBER    = `[-+]?\d*\.?\d+([eE][-+]?\d+)?`
	STRING    = `'[^']*' | "[^"]*"`
	COMMENT   = `#[^\n]*`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Value []*Value `parser:" '(' @@ ( ',' @@ )* ')' "`
}

type Boolean

type Boolean bool

func (*Boolean) Capture

func (b *Boolean) Capture(values []string) error

type Column

type Column struct {
	Name  string `parser:"( @Ident | @String )"`
	Alias string `parser:" ( 'AS' ( @Ident | @String | @'FROM' | @'NAMESPACE' | @'NS' | @'NAME' | @'SELECT' | @'LABEL' | @'DESC' ) )? "`
}

type Compare

type Compare struct {
	NOT bool   `parser:" @'NOT'? "`
	LHS string `parser:" ( @Ident | @String ) "`
	Op  string `parser:" @( '<>' | '<=' | '>=' | '=' | '==' | '<' | '>' | '!=' | 'NOT'? 'IN' ) "`
	RHS Value  `parser:" @@ "`
}

func (Compare) Filter

func (c Compare) Filter(i interface{}) bool

type Condition

type Condition struct {
	Type    string  `parser:" @( 'AND' | 'OR' ) "`
	Compare Compare `parser:" @@ "`
}

type DeleteStat

type DeleteStat struct {
	From              FromExpr            `parser:" 'DELETE' 'FROM' @@ "`
	Where             *WhereExpr          `parser:" ( 'WHERE' @@ )? "`
	Namespace         string              `parser:" ( ( 'NAMESPACE' | 'NS' ) ( @Ident | @String ) )? "`
	KubernetesFilters []*KubernetesFilter `parser:" @@* "`
}

type DescStat

type DescStat struct {
	Table string `parser:" 'DESC' @Ident "`
}

type FromExpr

type FromExpr struct {
	Table string `parser:" ( @Ident | @'NAMESPACE' | @'NS' | @'NAME' | @'SELECT' | @'LABEL' ) "`
	DB    string `parser:" ( '@' @Ident )? "`
}

type KSQL

type KSQL struct {
	Use    *UseStat    `parser:" @@* "`
	Select *SelectStat `parser:" @@* "`

	// TODO
	Delete *DeleteStat `parser:" @@* "`
	Update *UpdateStat `parser:" @@* "`

	Desc *DescStat `parser:" @@* "`
}

func Parse

func Parse(sql string) (*KSQL, error)

type KubernetesFilter

type KubernetesFilter struct {
	Label *LabelCompare `parser:"   'LABEL' @@ "`
	Name  *string       `parser:" | 'NAME' (@Ident | @String) "`
}

type LabelCompare

type LabelCompare struct {
	LHS       string         `parser:" ( @Ident | @String ) "`
	Operation LabelOperation `parser:" @@ "`
}

func (LabelCompare) IntoRequirement

func (c LabelCompare) IntoRequirement() (*labels.Requirement, error)

pub

type LabelOperation

type LabelOperation struct {
	Exists string `parser:" ( @( 'NOT'? 'EXISTS') "`
	Op     string `parser:" | @( '<>' | '<=' | '>=' | '=' | '==' | '!=' | 'NOT'? 'IN' ) "`
	RHS    Value  `parser:" @@ ) "`
}

type SelectExpr

type SelectExpr struct {
	ALL     bool      `parser:" @'*' "`
	Columns []*Column `parser:" | @@ ( ',' @@ )* "`
}

type SelectStat

type SelectStat struct {
	Select            SelectExpr          `parser:" 'SELECT' @@ "`
	From              FromExpr            `parser:" 'FROM' @@ "`
	Where             *WhereExpr          `parser:" ( 'WHERE' @@ )? "`
	Namespace         string              `parser:" ( ( 'NAMESPACE' | 'NS' ) ( @Ident | @String )? )? "`
	KubernetesFilters []*KubernetesFilter `parser:" @@* "`
}

type Statement

type Statement interface{}

type UpdateStat

type UpdateStat struct {
	Update bool `parser:" @'UPDATE' "`
}

TODO

type UseStat

type UseStat struct {
	// Database, we consider each cluster is a database.
	Database string `parser:" 'USE' @Ident "`
}

type Value

type Value struct {
	Number  *float64 ` parser:" ( @Number "`
	String  *string  ` parser:" | @String | @Ident "`
	Boolean *Boolean ` parser:" | @('TRUE' | 'FALSE') "`
	Null    bool     ` parser:" | @'NULL' "`
	Array   *Array   ` parser:" | @@ )"`
}

func (Value) Into

func (v Value) Into() []string

func (Value) IntoArray

func (v Value) IntoArray() []string

func (Value) IntoSingle

func (v Value) IntoSingle() string

type WhereExpr

type WhereExpr struct {
	First      Compare      `parser:" @@ "`
	Conditions []*Condition `parser:" @@* "`
}

Jump to

Keyboard shortcuts

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