Documentation ¶
Overview ¶
Package parser provides a parser and an Abstract Syntax Tree (AST) for the Pipeline Query Language.
Index ¶
- func SplitStatements(source string) []string
- func Walk(n Node, visit func(n Node) bool)
- type AsOperator
- type BasicLit
- type BinaryExpr
- type CallExpr
- type CountOperator
- type Expr
- type Ident
- type InExpr
- type IndexExpr
- type JoinOperator
- type Node
- type ParenExpr
- type ProjectColumn
- type ProjectOperator
- type QualifiedIdent
- type SortOperator
- type SortTerm
- type Span
- type SummarizeColumn
- type SummarizeOperator
- type TableRef
- type TabularDataSource
- type TabularExpr
- type TabularOperator
- type TakeOperator
- type Token
- type TokenKind
- type TopOperator
- type UnaryExpr
- type WhereOperator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SplitStatements ¶
SplitStatements splits the given string by semicolons.
Types ¶
type AsOperator ¶
AsOperator represents a `| as` operator in a TabularExpr. It implements TabularOperator.
func (*AsOperator) Span ¶
func (op *AsOperator) Span() Span
type BasicLit ¶
type BasicLit struct { ValueSpan Span Kind TokenKind // [TokenNumber] or [TokenString] Value string }
A BasicLit node represents a numeric or string literal.
func (*BasicLit) Float64 ¶
Float64 returns the numeric value of the literal as an unsigned integer. It returns 0 if the literal's kind is not TokenNumber.
func (*BasicLit) Uint64 ¶
Uint64 returns the numeric value of the literal as an unsigned integer. It returns 0 if the literal's kind is not TokenNumber.
type BinaryExpr ¶
A BinaryExpr represents a binary expression.
func (*BinaryExpr) Span ¶
func (expr *BinaryExpr) Span() Span
type CountOperator ¶
CountOperator represents a `| count` operator in a TabularExpr. It implements TabularOperator.
func (*CountOperator) Span ¶
func (op *CountOperator) Span() Span
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
Expr is the interface implemented by all expression AST node types.
type Ident ¶
type Ident struct { Name string NameSpan Span // Quoted is true if the identifier is quoted. Quoted bool }
An Ident node represents an identifier.
Ident does not implement Expr, but QualifiedIdent does. You can use *Ident.AsQualified to convert an *Ident to a *QualifiedIdent.
func (*Ident) AsQualified ¶
func (id *Ident) AsQualified() *QualifiedIdent
AsQualified converts the identifier to a QualifiedIdent with a single part.
type JoinOperator ¶
type JoinOperator struct { Pipe Span Keyword Span Kind Span KindAssign Span // Flavor is the type of join to use. // If absent, innerunique is implied. Flavor *Ident Lparen Span Right *TabularExpr Rparen Span On Span // Conditions is one or more AND-ed conditions. // If the expression is a single identifier x, // then it is treated as equivalent to "$left.x == $right.x". Conditions []Expr }
JoinOperator represents a `| join` operator in a TabularExpr. It implements TabularOperator.
func (*JoinOperator) Span ¶
func (op *JoinOperator) Span() Span
type Node ¶
type Node interface {
Span() Span
}
Node is the interface implemented by all AST node types.
type ProjectColumn ¶
A ProjectColumn is a single column term in a ProjectOperator. It consists of a column name, optionally followed by an expression specifying how to compute the column. If the expression is omitted, it is equivalent to using the Name as the expression.
func (*ProjectColumn) Span ¶
func (op *ProjectColumn) Span() Span
type ProjectOperator ¶
type ProjectOperator struct { Pipe Span Keyword Span Cols []*ProjectColumn }
ProjectOperator represents a `| project` operator in a TabularExpr. It implements TabularOperator.
func (*ProjectOperator) Span ¶
func (op *ProjectOperator) Span() Span
type QualifiedIdent ¶
type QualifiedIdent struct {
Parts []*Ident
}
A QualifiedIdent is one or more dot-separated identifiers.
func (*QualifiedIdent) Span ¶
func (id *QualifiedIdent) Span() Span
type SortOperator ¶
SortOperator represents a `| sort by` operator in a TabularExpr. It implements TabularOperator.
func (*SortOperator) Span ¶
func (op *SortOperator) Span() Span
type SortTerm ¶
SortTerm is a single sort constraint in the SortOperator.
type Span ¶
type Span struct { // Start is the index of the first byte of the span, // relative to the beginning of the query. Start int // End is the end index of the span (exclusive), // relative to the beginning of the query. End int }
A Span is a reference contiguous sequence of bytes in a query.
func (Span) IsValid ¶
IsValid reports whether the span has a non-negative length and non-negative indices.
type SummarizeColumn ¶
A SummarizeColumn is a single column term in a SummarizeOperator. It consists of an expression, optionally preceded by a column name. If the column name is omitted, one is derived from the expression.
func (*SummarizeColumn) Span ¶
func (op *SummarizeColumn) Span() Span
type SummarizeOperator ¶
type SummarizeOperator struct { Pipe Span Keyword Span Cols []*SummarizeColumn By Span GroupBy []*SummarizeColumn }
SummarizeOperator represents a `| summarize` operator in a TabularExpr. It implements TabularOperator.
func (*SummarizeOperator) Span ¶
func (op *SummarizeOperator) Span() Span
type TableRef ¶
type TableRef struct {
Table *Ident
}
A TableRef node refers to a specific table. It implements TabularDataSource.
type TabularDataSource ¶
type TabularDataSource interface { Node // contains filtered or unexported methods }
TabularDataSource is the interface implemented by all AST node types that can be used as the data source of a TabularExpr. At the moment, this can only be a TableRef.
type TabularExpr ¶
type TabularExpr struct { Source TabularDataSource Operators []TabularOperator }
TabularExpr is a query expression that produces a table.
func Parse ¶
func Parse(query string) (*TabularExpr, error)
Parse converts a Pipeline Query Language tabular expression into an Abstract Syntax Tree (AST).
func (*TabularExpr) Span ¶
func (x *TabularExpr) Span() Span
type TabularOperator ¶
type TabularOperator interface { Node // contains filtered or unexported methods }
TabularOperator is the interface implemented by all AST node types that can be used as operators in a TabularExpr.
type TakeOperator ¶
TakeOperator represents a `| take` operator in a TabularExpr. It implements TabularOperator.
func (*TakeOperator) Span ¶
func (op *TakeOperator) Span() Span
type Token ¶
type Token struct { // Kind is the token's type. Kind TokenKind // Span holds the location of the token. Span Span // Value contains kind-specific information about the token. // See the docs for [TokenKind] for what Value represents. Value string }
Token is a syntactical element in a query.
type TokenKind ¶
type TokenKind int
TokenKind is an enumeration of types of Token that can be returned by Scan.
const ( // TokenIdentifier is a plain identifier // that might be a keyword, depending on position. // The Value will be the identifier itself. TokenIdentifier TokenKind = 1 + iota // TokenQuotedIdentifier is an identifier // surrounded by backticks // The Value will be the content between the backticks // with any double backticks reduced. TokenQuotedIdentifier // TokenNumber is a numeric literal like "123", "3.14", "1e-9", or "0xdeadbeef". // The Value will be a decimal formatted string. TokenNumber // TokenString is a string literal enclosed by single or double quotes. // The Value will be the literal's value (i.e. any escape sequences are evaluated). TokenString // TokenAnd is the keyword "and". // The Value will be the empty string. TokenAnd // TokenOr is the keyword "or". // The Value will be the empty string. TokenOr // TokenPipe is a single pipe character ("|"). // The Value will be the empty string. TokenPipe // TokenDot is a period character ("."). // The Value will be the empty string. TokenDot // TokenDot is a comma character (","). // The Value will be the empty string. TokenComma // TokenPlus is a single plus character ("+"). // The Value will be the empty string. TokenPlus // TokenMinus is a single hyphen character ("-"). // The Value will be the empty string. TokenMinus // TokenStar is a single asterisk character ("*"). // The Value will be the empty string. TokenStar // TokenSlash is a single forward slash character ("/"). // The Value will be the empty string. TokenSlash // TokenMod is a single percent sign character ("%"). // The Value will be the empty string. TokenMod // TokenAssign is a single equals sign character ("="). // The Value will be the empty string. TokenAssign // TokenEq is a sequence of two equals sign characters ("=="). // The Value will be the empty string. TokenEq // TokenNE is the sequence "!=", representing an inequality test. // The Value will be the empty string. TokenNE // TokenLT is the less than symbol ("<"). // The Value will be the empty string. TokenLT // TokenLE is the less than or equal sequence "<=". // The Value will be the empty string. TokenLE // TokenGT is the greater than symbol (">"). // The Value will be the empty string. TokenGT // TokenGE is the greater than or equal sequence ">=". // The Value will be the empty string. TokenGE // TokenCaseInsensitiveEq is the sequence "=~". // The Value will be the empty string. TokenCaseInsensitiveEq // TokenCaseInsensitiveNE is the sequence "!~". // The Value will be the empty string. TokenCaseInsensitiveNE // TokenLParen is a left parenthesis. // The Value will be the empty string. TokenLParen // TokenRParen is a right parenthesis. // The Value will be the empty string. TokenRParen // TokenLBracket is a left bracket ("["). // The Value will be the empty string. TokenLBracket // TokenRBracket is a right bracket ("]"). // The Value will be the empty string. TokenRBracket // TokenBy is the keyword "in". // The Value will be the empty string. TokenIn // TokenBy is the keyword "by". // The Value will be the empty string. TokenBy // TokenSemi is the semicolon character (";"). // The Value will be the empty string. TokenSemi // TokenError is a marker for a scan error. // The Value will contain the error message. TokenError TokenKind = -1 )
Token kinds.
type TopOperator ¶
TopOperator represents a `| top` operator in a TabularExpr. It implements TabularOperator.
func (*TopOperator) Span ¶
func (op *TopOperator) Span() Span
type WhereOperator ¶
WhereOperator represents a `| where` operator in a TabularExpr. It implements TabularOperator.
func (*WhereOperator) Span ¶
func (op *WhereOperator) Span() Span