Documentation ¶
Overview ¶
Used to represent different nodes in the AST task add "Buy milk" due:2016-01-02 priority:high
Index ¶
- func Walk(v Visitor, node Node)
- func WalkList(v Visitor, nodes []Node)
- type AddCol
- type AddError
- type AddValue
- type BinaryExpression
- type BinaryOperator
- type Column
- type Command
- type CommandKind
- type Expression
- type ExpressionStatement
- func (stmt *ExpressionStatement) EvalInsert(transpiler *Transpiler) interface{}
- func (stmt *ExpressionStatement) EvalSelect(builder *sqlbuilder.SelectBuilder, addError AddError) interface{}
- func (stmt *ExpressionStatement) Expression()
- func (stmt *ExpressionStatement) Statement()
- func (stmt *ExpressionStatement) Type() NodeType
- type Key
- type Line
- type Literal
- func (lit *Literal) EvalInsert(transpiler *Transpiler) interface{}
- func (l *Literal) EvalSelect(builder *sqlbuilder.SelectBuilder, addError AddError) interface{}
- func (l *Literal) Expression()
- func (lit *Literal) ToPriorityInt() (db.TaskPriority, error)
- func (l *Literal) ToValue(transpiler *Transpiler) interface{}
- func (l *Literal) Type() NodeType
- type LiteralKind
- type LogicalExpression
- type LogicalOperator
- type Node
- type NodePosition
- type NodeType
- type Param
- type ParamDependency
- type ParamType
- type SqlArgs
- type SqlStatement
- type Statement
- type Tag
- type TagOperator
- type Transpile
- type TranspileCallback
- type TranspileError
- type Transpiler
- func (transpiler *Transpiler) AddCol(col string)
- func (transpiler *Transpiler) AddError(message error, node Node)
- func (transpiler *Transpiler) AddValue(value interface{})
- func (transpiler *Transpiler) Reset() *Transpiler
- func (transpiler *Transpiler) Transpile(command *Command, tx *sqlx.Tx) (SqlStatement, SqlArgs, []TranspileError)
- type TranspilerContext
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BinaryExpression ¶
type BinaryExpression struct { Left Node Operator BinaryOperator Right Node NodePosition }
BinaryExpression represents a binary expression. EXAMPLE: 1 + 2 Left: 1 Operator: + Right: 2
func (*BinaryExpression) EvalInsert ¶
func (bin *BinaryExpression) EvalInsert(transpiler *Transpiler) interface{}
func (*BinaryExpression) EvalSelect ¶
func (b *BinaryExpression) EvalSelect(builder *sqlbuilder.SelectBuilder, addError AddError) interface{}
func (*BinaryExpression) Expression ¶
func (b *BinaryExpression) Expression()
func (*BinaryExpression) Type ¶
func (b *BinaryExpression) Type() NodeType
type BinaryOperator ¶
type BinaryOperator int // BinaryOperator is an enum for binary operators.
const ( BinaryOperatorAdd BinaryOperator = iota // e.g 1 + 2 BinaryOperatorSub BinaryOperator = iota // e.g 1 - 2 BinaryOperatorMul BinaryOperator = iota // e.g 1 * 2 BinaryOperatorDiv BinaryOperator = iota // e.g 1 / 2 BinaryOperatorMod BinaryOperator = iota // e.g 1 % 2 BinaryOperatorEq BinaryOperator = iota // e.g 1 == 2 BinaryOperatorNe BinaryOperator = iota // e.g 1 != 2 BinaryOperatorLt BinaryOperator = iota // e.g 1 < 2 BinaryOperatorLe BinaryOperator = iota // e.g 1 <= 2 BinaryOperatorGt BinaryOperator = iota // e.g 1 > 2 BinaryOperatorGe BinaryOperator = iota // e.g 1 >= 2 )
type Command ¶
type Command struct { Kind CommandKind // Kind represents the type of command. e.g add Param *Param // Param represents a parameter in the command. e.g "buy dog" Options []Statement // Option represents an option in the command. e.g priority:high NodePosition }
Command represents a command in the AST. Example: add "buy dog" priority:high -----------------------^^^^^^^^^^^^^ options -------------^^^^^^^^^ parameter
func (*Command) EvalInsert ¶
func (c *Command) EvalInsert(transpiler *Transpiler) interface{}
func (*Command) EvalSelect ¶
type CommandKind ¶
type CommandKind int
const ( CommandKindAdd CommandKind = iota // e.g add "buy dog" CommandKindDepends // e.g depends 1 on 2 CommandKindList // e.g list +HOME CommandKindNext // e.g list +HOME )
func (*CommandKind) String ¶
func (c *CommandKind) String() string
type Expression ¶
type ExpressionStatement ¶
type ExpressionStatement struct { Expr Expression // binary, logical, tag, pair, literal NodePosition }
ExpressionStatement represents an expression statement. Example (Binary): 1 + 2 Example (Logical): 1 and 2 Example (Pair): priority:<High Example (Pair): priority:High Example (Literal): "high" Example (Tag): +HOME
func (*ExpressionStatement) EvalInsert ¶
func (stmt *ExpressionStatement) EvalInsert(transpiler *Transpiler) interface{}
func (*ExpressionStatement) EvalSelect ¶
func (stmt *ExpressionStatement) EvalSelect(builder *sqlbuilder.SelectBuilder, addError AddError) interface{}
func (*ExpressionStatement) Expression ¶
func (stmt *ExpressionStatement) Expression()
func (*ExpressionStatement) Statement ¶
func (stmt *ExpressionStatement) Statement()
func (*ExpressionStatement) Type ¶
func (stmt *ExpressionStatement) Type() NodeType
type Key ¶
type Key struct { Key string Expr Expression NodePosition }
============================================================================= Key =============================================================================
func (*Key) EvalInsert ¶
func (key *Key) EvalInsert(transpiler *Transpiler) interface{}
func (*Key) EvalSelect ¶
func (*Key) Expression ¶
func (key *Key) Expression()
type Literal ¶
type Literal struct { Value string // e.g "buy dog" Kind LiteralKind // e.g String/Number NodePosition }
Literal represents a literal value in the AST. Example (string): "buy dog" Example (number): 5
func (*Literal) EvalInsert ¶
func (lit *Literal) EvalInsert(transpiler *Transpiler) interface{}
func (*Literal) EvalSelect ¶
func (*Literal) Expression ¶
func (l *Literal) Expression()
func (*Literal) ToPriorityInt ¶
func (lit *Literal) ToPriorityInt() (db.TaskPriority, error)
ToPriorityInt converts the literal to a priority integer.
func (*Literal) ToValue ¶
func (l *Literal) ToValue(transpiler *Transpiler) interface{}
type LiteralKind ¶
type LiteralKind int // LiteralType is an enum for literal types.
const ( LiteralKindString LiteralKind = iota // e.g "buy dog" LiteralKindNumber LiteralKind = iota // e.g 5 )
func (*LiteralKind) String ¶
func (l *LiteralKind) String() string
type LogicalExpression ¶
type LogicalExpression struct { Left Node Operator LogicalOperator Right Node NodePosition }
LogicalExpression represents a logical expression. EXAMPLE (and): 1 and 2 EXAMPLE (or): 1 or 2
func (*LogicalExpression) EvalInsert ¶
func (logical *LogicalExpression) EvalInsert(transpiler *Transpiler) interface{}
func (*LogicalExpression) EvalSelect ¶
func (l *LogicalExpression) EvalSelect(builder *sqlbuilder.SelectBuilder, addError AddError) interface{}
func (*LogicalExpression) Expression ¶
func (l *LogicalExpression) Expression()
func (*LogicalExpression) Type ¶
func (l *LogicalExpression) Type() NodeType
type LogicalOperator ¶
type LogicalOperator int // LogicalOperator is an enum for logical operators.
const ( LogicalOperatorAnd LogicalOperator = iota // e.g 1 and 2 LogicalOperatorOr LogicalOperator = iota // e.g 1 or 2 )
type Node ¶
type Node interface { Type() NodeType StartColumn() Column EndColumn() Column StartLine() Line EndLine() Line Transpile }
Node represents a node in the AST.
type NodePosition ¶
type NodePosition struct {
// contains filtered or unexported fields
}
func (*NodePosition) EndColumn ¶
func (n *NodePosition) EndColumn() Column
func (*NodePosition) EndLine ¶
func (n *NodePosition) EndLine() Line
func (*NodePosition) StartColumn ¶
func (n *NodePosition) StartColumn() Column
Emulate the Node interface with embedded struct.
func (*NodePosition) StartLine ¶
func (n *NodePosition) StartLine() Line
type NodeType ¶
type NodeType int // NodeType represents the type of a node. e.g BinaryExpression, Literal, Command, etc.
const ( NodeTypeBinaryExpression NodeType = iota // NodeTypeBinaryExpression represents a binary expression. e.g 1 + 2 NodeTypeCommand // NodeTypeCommand represents a command. e.g add "buy dog" priority:High NodeTypeExpressionStatement // NodeTypeExpressionStatement represents an expression statement. e.g 1 + 2 NodeTypeLiteral // NodeTypeLiteral represents a literal. e.g "buy dog" NodeTypeLogicalExpression // NodeTypeLogicalExpression represents a logical expression. e.g 1 and 2 NodeTypeOption // NodeTypeOption represents an option. e.g priority:High NodeTypePair // NodeTypePair represents a pair. e.g priority:High NodeTypeParam // NodeTypeParam represents a param. e.g "buy dog" NodeTypeProgram // NodeTypeProgram represents a program. e.g add "buy dog" priority:High NodeTypeTag // NodeTypeTag represents a tag. e.g +tag )
type Param ¶
type Param struct { Kind ParamType // e.g TaskId, Description Value interface{} // e.g 1, "buy dog" NodePosition }
Param represents a parameter in the AST. Some command require parameters like `task 1 modify` Here the parameter is 1
func (*Param) EvalInsert ¶
func (p *Param) EvalInsert(transpiler *Transpiler) interface{}
func (*Param) EvalSelect ¶
func (*Param) Expression ¶
func (p *Param) Expression()
type ParamDependency ¶
ParamDependency represents a dependency parameter in the AST. Some command require dependencies like `task 1 depends 2`
type SqlStatement ¶
type SqlStatement string // SqlStatement is a SQL statement.
type Tag ¶
type Tag struct { Operator TagOperator // e.g. + or - Value string // e.g. HOME NodePosition }
Tag represents a tag in the AST. Example: +HOME Example: -HOME
func (*Tag) EvalInsert ¶
func (t *Tag) EvalInsert(transpiler *Transpiler) interface{}
func (*Tag) EvalSelect ¶
type TagOperator ¶
type TagOperator int // TagOperator is an enum for tag operators.
const ( TagOperatorPlus TagOperator = iota // e.g. +HOME TagOperatorMinus TagOperator = iota // e.g. -HOME )
type Transpile ¶
type Transpile interface { EvalSelect(*sqlbuilder.SelectBuilder, AddError) interface{} EvalInsert(*Transpiler) interface{} }
Transpile represents a node that can be transpiled to SQL.
type TranspileCallback ¶
TranspileCallback is a function that is called after the transpiler has executed a SQL statement. This is useful for executing additional SQL statements that are not part of the main transpilation process.
type TranspileError ¶
TranspileError represents an error that occurred during transpilation.
type Transpiler ¶
type Transpiler struct { Selecter *sqlbuilder.SelectBuilder // A select builder Inserter *sqlbuilder.InsertBuilder // An insert builder // contains filtered or unexported fields }
func NewTranspiler ¶
func NewTranspiler(store *db.Store) *Transpiler
NewTranspiler creates a new transpiler with the given store.
func (*Transpiler) AddCol ¶
func (transpiler *Transpiler) AddCol(col string)
AddCol adds a column to the transpilers SQL statement.
func (*Transpiler) AddError ¶
func (transpiler *Transpiler) AddError(message error, node Node)
AddError adds an error to the transpiler.
func (*Transpiler) AddValue ¶
func (transpiler *Transpiler) AddValue(value interface{})
AddValue adds a value to the transpilers SQL args.
func (*Transpiler) Reset ¶
func (transpiler *Transpiler) Reset() *Transpiler
Reset resets the transpiler to it's original state, ready for the next command.
func (*Transpiler) Transpile ¶
func (transpiler *Transpiler) Transpile( command *Command, tx *sqlx.Tx, ) (SqlStatement, SqlArgs, []TranspileError)
Transpile transpiles a command to a SQL statement.
type TranspilerContext ¶
type TranspilerContext struct {
// contains filtered or unexported fields
}