parser

package
v0.0.0-...-2533219 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package parser implements a parser for SQL statements

Inspired by go/parser

Index

Constants

View Source
const (
	SpaceToken = iota
	SemicolonToken
	CommaToken
	BracketOpeningToken
	BracketClosingToken
	LeftDipleToken
	RightDipleToken
	LessOrEqualToken
	GreaterOrEqualToken
	BacktickToken

	DoubleQuoteToken
	SimpleQuoteToken
	StarToken
	EqualityToken
	InequalityToken
	PeriodToken

	CreateToken
	SelectToken
	InsertToken
	UpdateToken
	DeleteToken
	ExplainToken
	TruncateToken
	DropToken
	GrantToken

	FromToken
	WhereToken
	TableToken
	IntoToken
	ValuesToken
	JoinToken
	OnToken
	IfToken
	NotToken
	ExistsToken
	NullToken
	AutoincrementToken
	CountToken
	SetToken
	OrderToken
	ByToken
	WithToken
	TimeToken
	ZoneToken
	ReturningToken
	InToken
	AndToken
	OrToken
	AscToken
	DescToken
	LimitToken
	IsToken
	ForToken
	DefaultToken
	LocalTimestampToken
	FalseToken
	UniqueToken
	NowToken
	OffsetToken

	TextToken
	IntToken
	PrimaryToken
	KeyToken
	StringToken
	NumberToken
	DateToken
)

SQL Tokens

View Source
const DateLongFormat = "2006-01-02 15:04:05.999999999 -0700 MST"

DateLongFormat is same as time.Time#String(), except this does not include monotonic time section

View Source
const DateNumberFormat = "2006-01-02"
View Source
const DateShortFormat = "2006-Jan-02"

DateShortFormat is a short format

Variables

This section is empty.

Functions

func ParseDate

func ParseDate(data string) (*time.Time, error)

ParseDate intends to parse all SQL date format

Types

type Decl

type Decl struct {
	Token  int
	Lexeme string
	Decl   []*Decl
}

Decl structure is the node to statement declaration tree

func NewDecl

func NewDecl(t Token) *Decl

NewDecl initialize a Decl struct from a given token

func (*Decl) Add

func (d *Decl) Add(subDecl *Decl)

Add creates a new leaf with given Decl

func (Decl) Stringy

func (d Decl) Stringy(depth int)

Stringy prints the declaration tree in console

type Instruction

type Instruction struct {
	Decls []*Decl
}

Instruction define a valid SQL statement

func ParseInstruction

func ParseInstruction(instruction string) ([]Instruction, error)

ParseInstruction calls lexer and parser, then return Decl tree for each instruction

func (Instruction) PrettyPrint

func (i Instruction) PrettyPrint()

PrettyPrint prints instruction's declarations on console with indentation

type Matcher

type Matcher func() bool

Matcher tries to match given string to an SQL token

type Token

type Token struct {
	Token  int
	Lexeme string
}

Token struct holds token id and it's lexeme

Jump to

Keyboard shortcuts

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