parser

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	EOF = -(iota + 1)
	UNCATEGORIZED
)
View Source
const (
	TOKEN_FROM   = IDENTIFIER
	TOKEN_TO     = SUBSTITUTION_OP
	KEYWORD_FROM = SELECT
	KEYWORD_TO   = VAR
)
View Source
const (
	SUBSTITUTION_OPERATOR = ":="

	VARIABLE_SIGN = '@'
)
View Source
const ADD = 57368
View Source
const AFTER = 57374
View Source
const ALL = 57397
View Source
const ALTER = 57370
View Source
const AND = 57401
View Source
const ANY = 57398
View Source
const AS = 57364
View Source
const ASC = 57383
View Source
const BEFORE = 57375
View Source
const BETWEEN = 57404
View Source
const BOOLEAN = 57350
View Source
const BREAK = 57431
View Source
const BY = 57382
View Source
const CASE = 57410
View Source
const CLOSE = 57424
View Source
const COMMIT = 57428
View Source
const COMPARISON_OP = 57435
View Source
const CONTINUE = 57430
View Source
const CREATE = 57367
View Source
const CROSS = 57392
View Source
const CURSOR = 57420
View Source
const DATETIME = 57352
View Source
const DATETIME_FORMAT = "2006-01-02 15:04:05.999999999"
View Source
const DECLARE = 57419
View Source
const DEFAULT = 57376
View Source
const DELETE = 57359
View Source
const DESC = 57384
View Source
const DISPOSE = 57425
View Source
const DISTINCT = 57408
View Source
const DO = 57417
View Source
const DROP = 57369
View Source
const DUAL = 57365
View Source
const ELSE = 57416
View Source
const ELSEIF = 57412
View Source
const END = 57418
View Source
const EXISTS = 57399
View Source
const EXIT = 57432
View Source
const FETCH = 57422
View Source
const FIRST = 57372
View Source
const FLAG = 57354
View Source
const FLOAT = 57349
View Source
const FOR = 57421
View Source
const FROM = 57356
View Source
const FULL = 57391
View Source
const GROUP = 57380
View Source
const GROUP_CONCAT = 57426
View Source
const HAVING = 57381
View Source
const IDENTIFIER = 57346
View Source
const IF = 57411
View Source
const IN = 57400
View Source
const INNER = 57387
View Source
const INSERT = 57361
View Source
const INTEGER = 57348
View Source
const INTO = 57362
View Source
const IS = 57406
View Source
const JOIN = 57386
View Source
const LAST = 57373
View Source
const LEFT = 57389
View Source
const LIKE = 57405
View Source
const LIMIT = 57385
View Source
const NATURAL = 57395
View Source
const NOT = 57403
View Source
const NULL = 57407
View Source
const ON = 57393
View Source
const OPEN = 57423
View Source
const OR = 57402
View Source
const ORDER = 57379
View Source
const OUTER = 57388
View Source
const PRINT = 57433
View Source
const RENAME = 57377
View Source
const RIGHT = 57390
View Source
const ROLLBACK = 57429
View Source
const SELECT = 57355
View Source
const SEPARATOR = 57427
View Source
const SET = 57358
View Source
const STDIN = 57366
View Source
const STRING = 57347
View Source
const STRING_OP = 57436
View Source
const SUBSTITUTION_OP = 57437
View Source
const TABLE = 57371
View Source
const TERNARY = 57351
View Source
const THEN = 57415
View Source
const TO = 57378
View Source
const TOKEN_UNDEFINED = 0
View Source
const UNION = 57396
View Source
const UPDATE = 57357
View Source
const USING = 57394
View Source
const VALUES = 57363
View Source
const VAR = 57434
View Source
const VARIABLE = 57353
View Source
const WHEN = 57414
View Source
const WHERE = 57360
View Source
const WHILE = 57413
View Source
const WITH = 57409

Variables

This section is empty.

Functions

func Float64ToStr

func Float64ToStr(f float64) string

func FormatTableName added in v0.1.6

func FormatTableName(s string) string

func Int64ToStr

func Int64ToStr(i int64) string

func IsNull

func IsNull(v Primary) bool

func IsPrimary

func IsPrimary(e Expression) bool

func SetDebugLevel

func SetDebugLevel(level int, verbose bool)
Example
SetDebugLevel(0, false)
_, err := Parse("select select")
fmt.Println(err)

SetDebugLevel(0, true)
_, err = Parse("select select")
fmt.Println(err)
Output:

syntax error
syntax error: unexpected SELECT

func StrToTime

func StrToTime(s string) (time.Time, error)

func TokenLiteral

func TokenLiteral(token int) string

Types

type AddColumns added in v0.1.6

type AddColumns struct {
	AlterTable string
	Table      Identifier
	Add        string
	Columns    []Expression
	Position   Expression
}

func (AddColumns) String added in v0.1.6

func (e AddColumns) String() string

type All

type All struct {
	All      string
	LHS      Expression
	Operator Token
	Query    Subquery
}

func (All) String

func (a All) String() string

type AllColumns

type AllColumns struct {
}

func (AllColumns) String

func (ac AllColumns) String() string

type Any

type Any struct {
	Any      string
	LHS      Expression
	Operator Token
	Query    Subquery
}

func (Any) String

func (a Any) String() string

type Arithmetic

type Arithmetic struct {
	LHS      Expression
	Operator int
	RHS      Expression
}

func (Arithmetic) String

func (a Arithmetic) String() string

type Between

type Between struct {
	Between  string
	And      string
	LHS      Expression
	Low      Expression
	High     Expression
	Negation Token
}

func (*Between) IsNegated

func (b *Between) IsNegated() bool

func (Between) String

func (b Between) String() string

type Boolean

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

func NewBoolean

func NewBoolean(b bool) Boolean

func (Boolean) Bool

func (b Boolean) Bool() bool

func (Boolean) String

func (b Boolean) String() string

func (Boolean) Ternary

func (b Boolean) Ternary() ternary.Value

type Case

type Case struct {
	Case  string
	End   string
	Value Expression
	When  []Expression
	Else  Expression
}

func (Case) String

func (c Case) String() string

type CaseElse

type CaseElse struct {
	Else   string
	Result Expression
}

func (CaseElse) String

func (ce CaseElse) String() string

type CaseWhen

type CaseWhen struct {
	When      string
	Then      string
	Condition Expression
	Result    Expression
}

func (CaseWhen) String

func (cw CaseWhen) String() string

type CloseCursor added in v0.1.8

type CloseCursor struct {
	Cursor Identifier
}

type ColumnDefault added in v0.1.6

type ColumnDefault struct {
	Column  Identifier
	Default string
	Value   Expression
}

func (ColumnDefault) String added in v0.1.6

func (e ColumnDefault) String() string

type ColumnPosition added in v0.1.6

type ColumnPosition struct {
	Position Token
	Column   Expression
}

func (ColumnPosition) String added in v0.1.6

func (e ColumnPosition) String() string

type Comparison

type Comparison struct {
	LHS      Expression
	Operator Token
	RHS      Expression
}

func (Comparison) String

func (c Comparison) String() string

type Concat

type Concat struct {
	Items []Expression
}

func (Concat) String

func (c Concat) String() string

type CreateTable added in v0.1.6

type CreateTable struct {
	CreateTable string
	Table       Identifier
	Fields      []Expression
}

func (CreateTable) String added in v0.1.6

func (e CreateTable) String() string

type CursorDeclaration added in v0.1.8

type CursorDeclaration struct {
	Cursor Identifier
	Query  SelectQuery
}

type Datetime

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

func NewDatetime

func NewDatetime(t time.Time) Datetime

func NewDatetimeFromString

func NewDatetimeFromString(s string) Datetime

func (Datetime) Bool

func (dt Datetime) Bool() bool

func (Datetime) Format

func (dt Datetime) Format() string

func (*Datetime) SetFormat

func (dt *Datetime) SetFormat(format string)

func (Datetime) String

func (dt Datetime) String() string

func (Datetime) Ternary

func (dt Datetime) Ternary() ternary.Value

func (Datetime) Value

func (dt Datetime) Value() time.Time

type DeleteQuery added in v0.1.6

type DeleteQuery struct {
	Delete      string
	Tables      []Expression
	FromClause  Expression
	WhereClause Expression
}

func (DeleteQuery) String added in v0.1.6

func (dq DeleteQuery) String() string

type DisposeCursor added in v0.1.8

type DisposeCursor struct {
	Cursor Identifier
}

type DropColumns added in v0.1.6

type DropColumns struct {
	AlterTable string
	Table      Identifier
	Drop       string
	Columns    []Expression
}

func (DropColumns) String added in v0.1.6

func (e DropColumns) String() string

type Dual

type Dual struct {
	Dual string
}

func (Dual) String

func (d Dual) String() string

type Else added in v0.1.8

type Else struct {
	Statements []Statement
}

type ElseIf added in v0.1.8

type ElseIf struct {
	Condition  Expression
	Statements []Statement
}

type Exists

type Exists struct {
	Exists string
	Query  Subquery
}

func (Exists) String

func (e Exists) String() string

type Expression

type Expression interface {
	String() string
}

type FetchCursor added in v0.1.8

type FetchCursor struct {
	Cursor    Identifier
	Variables []Variable
}

type Field

type Field struct {
	Object Expression
	As     Token
	Alias  Expression
}

func (*Field) Name

func (f *Field) Name() string

func (Field) String

func (f Field) String() string

type FieldReference added in v0.1.8

type FieldReference struct {
	View   Expression
	Column Identifier
}

func (FieldReference) String added in v0.1.8

func (e FieldReference) String() string

type Float

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

func NewFloat

func NewFloat(f float64) Float

func NewFloatFromString

func NewFloatFromString(s string) Float

func (Float) Bool

func (f Float) Bool() bool

func (Float) String

func (f Float) String() string

func (Float) Ternary

func (f Float) Ternary() ternary.Value

func (Float) Value

func (f Float) Value() float64

type FlowControl added in v0.1.8

type FlowControl struct {
	Token int
}

type FromClause

type FromClause struct {
	From   string
	Tables []Expression
}

func (FromClause) String

func (f FromClause) String() string

type Function

type Function struct {
	Name   string
	Option Option
}

func (Function) String

func (f Function) String() string

type GroupByClause

type GroupByClause struct {
	GroupBy string
	Items   []Expression
}

func (GroupByClause) String

func (gb GroupByClause) String() string

type GroupConcat

type GroupConcat struct {
	GroupConcat  string
	Option       Option
	OrderBy      Expression
	SeparatorLit string
	Separator    string
}

func (GroupConcat) String

func (gc GroupConcat) String() string

type HavingClause

type HavingClause struct {
	Having string
	Filter Expression
}

func (HavingClause) String

func (h HavingClause) String() string

type Identifier

type Identifier struct {
	Literal string
	Quoted  bool
}

func (Identifier) String

func (i Identifier) String() string

type If added in v0.1.8

type If struct {
	Condition  Expression
	Statements []Statement
	ElseIf     []ProcExpr
	Else       ProcExpr
}

type In

type In struct {
	In       string
	LHS      Expression
	List     []Expression
	Query    Subquery
	Negation Token
}

func (*In) IsNegated

func (i *In) IsNegated() bool

func (In) String

func (i In) String() string

type InsertQuery added in v0.1.6

type InsertQuery struct {
	Insert     string
	Into       string
	Table      Identifier
	Fields     []Expression
	Values     string
	ValuesList []Expression
	Query      Expression
}

func (InsertQuery) String added in v0.1.6

func (iq InsertQuery) String() string

type InsertValues added in v0.1.6

type InsertValues struct {
	Values []Expression
}

func (InsertValues) String added in v0.1.6

func (iv InsertValues) String() string

type Integer

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

func NewInteger

func NewInteger(i int64) Integer

func NewIntegerFromString

func NewIntegerFromString(s string) Integer

func (Integer) Bool

func (i Integer) Bool() bool

func (Integer) String

func (i Integer) String() string

func (Integer) Ternary

func (i Integer) Ternary() ternary.Value

func (Integer) Value

func (i Integer) Value() int64

type Is

type Is struct {
	Is       string
	LHS      Expression
	RHS      Expression
	Negation Token
}

func (*Is) IsNegated

func (i *Is) IsNegated() bool

func (Is) String

func (i Is) String() string

type Join

type Join struct {
	Join      string
	Table     Table
	JoinTable Table
	Natural   Token
	JoinType  Token
	Direction Token
	Condition Expression
}

func (Join) String

func (j Join) String() string

type JoinCondition

type JoinCondition struct {
	Literal string
	On      Expression
	Using   []Expression
}

func (JoinCondition) String

func (jc JoinCondition) String() string

type Lexer

type Lexer struct {
	Scanner
	// contains filtered or unexported fields
}

func (*Lexer) Error

func (l *Lexer) Error(e string)

func (*Lexer) Lex

func (l *Lexer) Lex(lval *yySymType) int

type Like

type Like struct {
	Like     string
	LHS      Expression
	Pattern  Expression
	Negation Token
}

func (*Like) IsNegated

func (l *Like) IsNegated() bool

func (Like) String

func (l Like) String() string

type LimitClause

type LimitClause struct {
	Limit  string
	Number int64
}

func (LimitClause) String

func (l LimitClause) String() string

type Logic

type Logic struct {
	LHS      Expression
	Operator Token
	RHS      Expression
}

func (Logic) String

func (l Logic) String() string

type Null

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

func NewNull

func NewNull() Null

func NewNullFromString

func NewNullFromString(s string) Null

func (Null) Bool

func (n Null) Bool() bool

func (Null) String

func (n Null) String() string

func (Null) Ternary

func (n Null) Ternary() ternary.Value

type OpenCursor added in v0.1.8

type OpenCursor struct {
	Cursor Identifier
}

type Option

type Option struct {
	Distinct Token
	Args     []Expression
}

func (Option) IsDistinct

func (o Option) IsDistinct() bool

func (Option) String

func (o Option) String() string

type OrderByClause

type OrderByClause struct {
	OrderBy string
	Items   []Expression
}

func (OrderByClause) String

func (ob OrderByClause) String() string

type OrderItem

type OrderItem struct {
	Item      Expression
	Direction Token
}

func (OrderItem) String

func (oi OrderItem) String() string

type Parentheses

type Parentheses struct {
	Expr Expression
}

func (Parentheses) String

func (p Parentheses) String() string

type Primary

type Primary interface {
	String() string
	Bool() bool
	Ternary() ternary.Value
}

func Float64ToPrimary

func Float64ToPrimary(f float64) Primary

func PrimaryToBoolean

func PrimaryToBoolean(p Primary) Primary

func PrimaryToDatetime

func PrimaryToDatetime(p Primary) Primary

func PrimaryToFloat

func PrimaryToFloat(p Primary) Primary

func PrimaryToInteger

func PrimaryToInteger(p Primary) Primary

func PrimaryToString

func PrimaryToString(p Primary) Primary

type Print added in v0.1.6

type Print struct {
	Value Expression
}

type ProcExpr added in v0.1.8

type ProcExpr interface{}

type RenameColumn added in v0.1.6

type RenameColumn struct {
	AlterTable string
	Table      Identifier
	Rename     string
	Old        FieldReference
	To         string
	New        Identifier
}

func (RenameColumn) String added in v0.1.6

func (e RenameColumn) String() string

type Scanner

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

func (*Scanner) Init

func (s *Scanner) Init(src string) *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan() (int, string, bool, error)

type SelectClause

type SelectClause struct {
	Select   string
	Distinct Token
	Fields   []Expression
}

func (SelectClause) IsDistinct

func (sc SelectClause) IsDistinct() bool

func (SelectClause) String

func (sc SelectClause) String() string

type SelectQuery

type SelectQuery struct {
	SelectClause  Expression
	FromClause    Expression
	WhereClause   Expression
	GroupByClause Expression
	HavingClause  Expression
	OrderByClause Expression
	LimitClause   Expression
}

func (SelectQuery) String

func (sq SelectQuery) String() string

type SetFlag added in v0.1.6

type SetFlag struct {
	Name  string
	Value Primary
}

type Statement

type Statement interface{}

func Parse

func Parse(s string) ([]Statement, error)

type Stdin added in v0.1.5

type Stdin struct {
	Stdin string
}

func (Stdin) String added in v0.1.5

func (si Stdin) String() string

type String

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

func NewString

func NewString(s string) String

func (String) Bool

func (s String) Bool() bool

func (String) String

func (s String) String() string

func (String) Ternary

func (s String) Ternary() ternary.Value

func (String) Value

func (s String) Value() string

type Subquery

type Subquery struct {
	Query SelectQuery
}

func (Subquery) String

func (sq Subquery) String() string

type Table

type Table struct {
	Object Expression
	As     Token
	Alias  Expression
}

func (*Table) Name

func (t *Table) Name() string

func (Table) String

func (t Table) String() string

type Ternary

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

func NewTernary

func NewTernary(t ternary.Value) Ternary

func NewTernaryFromString

func NewTernaryFromString(s string) Ternary

func (Ternary) Bool

func (t Ternary) Bool() bool

func (Ternary) String

func (t Ternary) String() string

func (Ternary) Ternary

func (t Ternary) Ternary() ternary.Value

type Token

type Token struct {
	Token   int
	Literal string
	Quoted  bool
}

func (*Token) IsEmpty

func (t *Token) IsEmpty() bool

type TransactionControl added in v0.1.8

type TransactionControl struct {
	Token int
}

type UpdateQuery added in v0.1.6

type UpdateQuery struct {
	Update      string
	Tables      []Expression
	Set         string
	SetList     []Expression
	FromClause  Expression
	WhereClause Expression
}

func (UpdateQuery) String added in v0.1.6

func (uq UpdateQuery) String() string

type UpdateSet added in v0.1.6

type UpdateSet struct {
	Field FieldReference
	Value Expression
}

func (UpdateSet) String added in v0.1.6

func (us UpdateSet) String() string

type Variable

type Variable struct {
	Name string
}

func (Variable) String

func (v Variable) String() string

type VariableAssignment

type VariableAssignment struct {
	Name  string
	Value Expression
}

func (VariableAssignment) String

func (va VariableAssignment) String() string

type VariableDeclaration

type VariableDeclaration struct {
	Assignments []Expression
}

type VariableSubstitution

type VariableSubstitution struct {
	Variable Variable
	Value    Expression
}

func (VariableSubstitution) String

func (vs VariableSubstitution) String() string

type WhereClause

type WhereClause struct {
	Where  string
	Filter Expression
}

func (WhereClause) String

func (w WhereClause) String() string

type While added in v0.1.8

type While struct {
	Condition  Expression
	Statements []Statement
}

type WhileInCursor added in v0.1.8

type WhileInCursor struct {
	Variables  []Variable
	Cursor     Identifier
	Statements []Statement
}

Jump to

Keyboard shortcuts

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