parser

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package parser implements a parser for SQL statements

Inspired by go/parser

Package parser implements a parser for SQL statements

Inspired by go/parser

Package parser implements a parser for SQL statements

Inspired by go/parser

Index

Constants

View Source
const (
	ActionToken         = iota // Second-order
	AndToken                   // Second-order
	AsToken                    // Second-order
	AscToken                   // Second-order
	AutoincrementToken         // Second-order
	BacktickToken              // Punctuation
	BracketClosingToken        // Punctuation
	BracketOpeningToken        // Punctuation
	BtreeToken                 // Second-order
	ByToken                    // Second-order
	CascadeToken               // Second-order
	CharacterToken             // Second-order
	CharsetToken               // Second-order
	CommaToken                 // Punctuation
	ConstraintToken            // Second-order
	CountToken                 // Second-order
	CreateToken                // First-order
	DateToken                  // Type
	DefaultToken               // Second-order
	DeleteToken                // First-order
	DescToken                  // Second-order
	DoubleQuoteToken           // Quote
	DropToken                  // First-order
	EngineToken                // Second-order
	EqualityToken              // Quote
	ExistsToken                // Second-order
	ExplainToken               // First-order
	FalseToken                 // Second-order
	ForToken                   // Second-order
	ForeignToken               // Second-order
	FromToken                  // Second-order
	FullToken                  // Second-order
	GrantToken                 // First-order
	GreaterOrEqualToken        // Punctuation
	HashToken                  // Second-order
	IfToken                    // Second-order
	InToken                    // Second-order
	IndexToken                 // Second-order
	InnerToken                 // Second-order
	InsertToken                // First-order
	IntToken                   // Type
	IntoToken                  // Second-order
	IsToken                    // Second-order
	JoinToken                  // Second-order
	KeyToken                   // Type
	LeftToken                  // Second-order
	LeftDipleToken             // Punctuation
	LessOrEqualToken           // Punctuation
	LimitToken                 // Second-order
	LocalTimestampToken        // Second-order
	MatchToken                 // Second-order
	NoToken                    // Second-order
	NotToken                   // Second-order
	NowToken                   // Second-order
	NullToken                  // Second-order
	NumberToken                // Type
	OffsetToken                // Second-order
	OnToken                    // Second-order
	OrToken                    // Second-order
	OrderToken                 // Second-order
	OuterToken                 // Second-order
	PartialToken               // Quote
	PeriodToken                // Quote
	PrimaryToken               // Type
	ReferencesToken            // Second-order
	ReturningToken             // Second-order
	RestrictToken              // Second-order
	RightToken                 // Second-order
	RightDipleToken            // Punctuation
	SelectToken                // First-order
	SemicolonToken             // Punctuation
	SetToken                   // Second-order
	SimpleToken                // Second-order
	SimpleQuoteToken           // Quote
	SpaceToken                 // Punctuation
	StarToken                  // Quote
	StringToken                // Type
	TableToken                 // Second-order
	TextToken                  // Type
	TimeToken                  // Second-order
	TrueToken                  // Second-order
	TruncateToken              // First-order
	UniqueToken                // Second-order
	UpdateToken                // First-order
	UsingToken                 // Second-order
	ValuesToken                // Second-order
	WhereToken                 // Second-order
	WithToken                  // Second-order
	ZoneToken                  // Second-order
)

SQL Tokens

View Source
const DateLongFormat = time.RFC3339Nano

DateLongFormat is same as time.RFC3339Nano

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

DateNumberFormat is a fully numeric short date format

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

DateShortFormat is a short date format with human-readable month element

Variables

This section is empty.

Functions

func NewParser added in v0.0.8

func NewParser(tokens []Token) parser

NewParser returns a parser object initialized with a list of tokens

func ParseDate

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

ParseDate intends to parse all SQL date formats

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 contains a token id and its lexeme TODO: Add Location{Path string, Line int, Offset int}

func (Token) IsAWord added in v0.0.10

func (u Token) IsAWord() bool

IsAWord is used to tell if a keyword token is effectively a string (i.e. a word)

Jump to

Keyboard shortcuts

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