parser

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 8 Imported by: 77

Documentation

Index

Constants

View Source
const (
	LongVarBinary int
	LongVarChar
	GeometryCollection
	GeomCollection
	LineString
	MultiLineString
	MultiPoint
	MultiPolygon
	Point
	Polygon
	Json
	Geometry
	Enum
	Set
	Bit
	Time
	Timestamp
	DateTime
	Binary
	VarBinary
	Blob
	Year
	Decimal
	Dec
	Fixed
	Numeric
	Float
	Float4
	Float8
	Double
	Real
	TinyInt
	SmallInt
	MediumInt
	Int
	Integer
	BigInt
	MiddleInt
	Int1
	Int2
	Int3
	Int4
	Int8
	Date
	TinyBlob
	MediumBlob
	LongBlob
	Bool
	Boolean
	Serial
	NVarChar
	NChar
	Char
	Character
	VarChar
	TinyText
	Text
	MediumText
	LongText
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceptor

type Acceptor func(p *gen.MySqlParser, visitor *visitor) interface{}

Acceptor is the alias of function

type CaseChangingStream

type CaseChangingStream struct {
	antlr.CharStream
	// contains filtered or unexported fields
}

func (*CaseChangingStream) LA

func (is *CaseChangingStream) LA(offset int) int

LA gets the value of the symbol at offset from the current position from the underlying CharStream and converts it to either upper case or lower case.

type Column

type Column struct {
	Name       string
	DataType   DataType
	Constraint *ColumnConstraint
}

type ColumnConstraint

type ColumnConstraint struct {
	NotNull         bool
	HasDefaultValue bool
	AutoIncrement   bool
	Primary         bool
	Key             bool
	Unique          bool
	Comment         string
}

type ColumnDeclaration

type ColumnDeclaration struct {
	Name             string
	ColumnDefinition *ColumnDefinition
}

type ColumnDefinition

type ColumnDefinition struct {
	DataType         DataType
	ColumnConstraint *ColumnConstraint
}

type CreateTable

type CreateTable struct {
	// Name describes the literal of table, this name can be specified as db_name.tbl_name,
	// https://dev.mysql.com/doc/refman/8.0/en/create-table.html#create-table-name
	Name        string
	Columns     []*ColumnDeclaration
	Constraints []*TableConstraint
}

func (*CreateTable) Convert

func (c *CreateTable) Convert() *Table

type DataType

type DataType interface {
	Type() int
	Unsigned() bool
	// Value returns the values if the data type is Enum or Set
	Value() []string
}

DataType describes the data type and value of the column in table

type EnumSetDataType

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

EnumSetDataType describes the data type Enum and Set of column

func (*EnumSetDataType) Type

func (e *EnumSetDataType) Type() int

Type returns the data type of column

func (*EnumSetDataType) Unsigned added in v1.0.4

func (e *EnumSetDataType) Unsigned() bool

Unsigned returns true if the data type is unsigned.

func (*EnumSetDataType) Value

func (e *EnumSetDataType) Value() []string

Value returns the value of data type Enum and Set

type NormalDataType

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

NormalDataType describes the data type which not contains Enum and Set of column

func (*NormalDataType) Type

func (n *NormalDataType) Type() int

Type returns the data type of column

func (*NormalDataType) Unsigned added in v1.0.4

func (n *NormalDataType) Unsigned() bool

Unsigned returns true if the data type is unsigned.

func (*NormalDataType) Value

func (n *NormalDataType) Value() []string

Value returns nil default

type Option

type Option func(p *Parser)

Option is the alias of function.

func WithConsole

func WithConsole(logger console.Console) Option

WithConsole is a Parser option to set console.

func WithDebugMode

func WithDebugMode(debug bool) Option

WithDebugMode is a Parser option to set debug mode.

type Parser

type Parser struct {
	antlr.DefaultErrorListener
	// contains filtered or unexported fields
}

Parser is the syntax entry to parse sql as AST, you can use NewParser to create an instance with options, WithDebugMode option can parse sql with debug, WithLogger option can print logs while parsing.

func NewParser

func NewParser(options ...Option) *Parser

NewParser creates an instance of Parser.

func (*Parser) From

func (p *Parser) From(filename string) (ret []*Table, err error)

func (*Parser) SyntaxError

func (p *Parser) SyntaxError(_ antlr.Recognizer, _ interface{}, line, column int, msg string, _ antlr.RecognitionException)

SyntaxError overrides SyntaxError from antlr.DefaultErrorListener, which could catch error from this function, and panic, the parser would catch the panic by testMysqlSyntax and returns.

type Table

type Table struct {
	Name        string
	Columns     []*Column
	Constraints []*TableConstraint
}

type TableConstraint

type TableConstraint struct {
	// ColumnPrimaryKey describes the name of columns
	ColumnPrimaryKey []string
	// ColumnUniqueKey describes the name of columns
	ColumnUniqueKey []string
}

type Token

type Token interface {
	GetLine() int
	GetColumn() int
	GetText() string
	SetText(s string)
}

Token is an abstraction from each lexical element, literal, etc.

Jump to

Keyboard shortcuts

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