token

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 5 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Keywords = []TokenKind{
	"ALL",
	"AND",
	"ANY",
	"ARRAY",
	"AS",
	"ASC",
	"ASSERT_ROWS_MODIFIED",
	"AT",
	"BETWEEN",
	"BY",
	"CASE",
	"CAST",
	"COLLATE",
	"CONTAINS",
	"CREATE",
	"CROSS",
	"CUBE",
	"CURRENT",
	"DEFAULT",
	"DEFINE",
	"DESC",
	"DISTINCT",
	"ELSE",
	"END",
	"ENUM",
	"ESCAPE",
	"EXCEPT",
	"EXCLUDE",
	"EXISTS",
	"EXTRACT",
	"FALSE",
	"FETCH",
	"FOLLOWING",
	"FOR",
	"FROM",
	"FULL",
	"GRAPH_TABLE",
	"GROUP",
	"GROUPING",
	"GROUPS",
	"HASH",
	"HAVING",
	"IGNORE",
	"IF",
	"IN",
	"INNER",
	"INTERSECT",
	"INTERVAL",
	"INTO",
	"IS",
	"JOIN",
	"LATERAL",
	"LEFT",
	"LIKE",
	"LIMIT",
	"LOOKUP",
	"MERGE",
	"NATURAL",
	"NEW",
	"NO",
	"NOT",
	"NULL",
	"NULLS",
	"OF",
	"ON",
	"OR",
	"ORDER",
	"OUTER",
	"OVER",
	"PARTITION",
	"PRECEDING",
	"PROTO",
	"RANGE",
	"RECURSIVE",
	"RESPECT",
	"RIGHT",
	"ROLLUP",
	"ROWS",
	"SELECT",
	"SET",
	"SOME",
	"STRUCT",
	"TABLESAMPLE",
	"THEN",
	"TO",
	"TREAT",
	"TRUE",
	"UNBOUNDED",
	"UNION",
	"UNNEST",
	"USING",
	"WHEN",
	"WHERE",
	"WINDOW",
	"WITH",
	"WITHIN",
}
View Source
var KeywordsMap map[TokenKind]struct{}

Functions

func IsKeyword

func IsKeyword(s string) bool

func QuoteSQLBytes

func QuoteSQLBytes(bs []byte) string

QuoteSQLBytes returns quoted string with SQL bytes escaping.

func QuoteSQLIdent

func QuoteSQLIdent(s string) string

QuoteSQLIdent returns quoted identifier if needed, otherwise it returns the input string.

func QuoteSQLString

func QuoteSQLString(s string) string

QuoteSQLString returns quoted string with SQL string escaping.

Types

type File

type File struct {
	FilePath string
	Buffer   string
	// contains filtered or unexported fields
}

File is input file with source code.

func (*File) Position

func (f *File) Position(pos, end Pos) *Position

Position returns a new Position from pos and end on this File.

func (*File) ResolvePos

func (f *File) ResolvePos(pos Pos) (line int, column int)

ResolvePos returns line and column number from pos.

type Pos

type Pos int

Pos is just source code position.

Internally it is zero-origin offset of the buffer.

const InvalidPos Pos = -1

func (Pos) Invalid

func (p Pos) Invalid() bool

Invalid returns whether p is invalid Pos or not.

type Position

type Position struct {
	FilePath string
	Pos, End Pos

	// Line and Column are 0-origin.
	Line, Column       int
	EndLine, EndColumn int

	// Source is source code around this position with line number and cursor
	// for detailed error message.
	Source string
}

Position is source code position with file path and source code around this position.

func (*Position) String

func (pos *Position) String() string

type Token

type Token struct {
	Kind     TokenKind
	Comments []TokenComment
	Space    string
	Raw      string
	AsString string // available for TokenIdent, TokenString and TokenBytes
	Base     int    // 10 or 16 on TokenInt
	Pos, End Pos
}

func (*Token) Clone

func (t *Token) Clone() *Token

func (*Token) IsIdent

func (t *Token) IsIdent(s string) bool

func (*Token) IsKeywordLike

func (t *Token) IsKeywordLike(s string) bool

type TokenComment

type TokenComment struct {
	Space    string // leading spaces
	Raw      string
	Pos, End Pos
}

type TokenKind

type TokenKind string
const (
	TokenBad    TokenKind = "<bad>"
	TokenEOF    TokenKind = "<eof>"
	TokenIdent  TokenKind = "<ident>"
	TokenParam  TokenKind = "<param>"
	TokenInt    TokenKind = "<int>"
	TokenFloat  TokenKind = "<float>"
	TokenString TokenKind = "<string>"
	TokenBytes  TokenKind = "<bytes>"
)

Jump to

Keyboard shortcuts

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