scanner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tokstr

func Tokstr(tok Token, lit string) string

Tokstr returns a literal if provided, otherwise returns the token string.

Types

type Pos

type Pos struct {
	Line int
	Char int
}

Pos specifies the line and character position of a token. The Char and Line are both zero-based indexes.

type Scanner

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

Scanner represents a buffered scanner. It provides a fixed-length circular buffer that can be unread.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new buffered scanner for a reader.

func (*Scanner) Curr

func (s *Scanner) Curr() (tok Token, pos Pos, lit string)

Curr returns the last read token.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, pos Pos, lit string)

Scan reads the next token from the scanner.

func (*Scanner) ScanRegex

func (s *Scanner) ScanRegex() (tok Token, pos Pos, lit string)

ScanRegex reads a regex token from the scanner.

func (*Scanner) Unscan

func (s *Scanner) Unscan()

Unscan pushes the previously token back onto the buffer.

type Token

type Token int

Token is a lexical token of the Genji SQL language.

const (
	// ILLEGAL Token, EOF, WS are Special Genji SQL tokens.
	ILLEGAL Token = iota
	EOF
	WS
	COMMENT

	// IDENT and the following are Genji SQL literal tokens.
	IDENT           // main
	NAMEDPARAM      // $param
	POSITIONALPARAM // ?
	NUMBER          // 12345.67
	INTEGER         // 12345
	STRING          // "abc"
	BADSTRING       // "abc
	BADESCAPE       // \q
	TRUE            // true
	FALSE           // false
	NULL            // NULL
	REGEX           // Regular expressions
	BADREGEX        // `.*

	// ADD and the following are Genji SQL Operators
	ADD        // +
	SUB        // -
	MUL        // *
	DIV        // /
	MOD        // %
	BITWISEAND // &
	BITWISEOR  // |
	BITWISEXOR // ^
	BETWEEN    // BETWEEN

	AND // AND
	OR  // OR

	EQ       // =
	NEQ      // !=
	EQREGEX  // =~
	NEQREGEX // !~
	LT       // <
	LTE      // <=
	GT       // >
	GTE      // >=
	IN       // IN
	NIN      // NOT IN
	IS       // IS
	ISN      // IS NOT
	LIKE     // LIKE
	CONCAT   // ||

	LPAREN      // (
	RPAREN      // )
	LBRACKET    // {
	RBRACKET    // }
	LSBRACKET   // [
	RSBRACKET   // ]
	COMMA       // ,
	COLON       // :
	DOUBLECOLON // ::
	SEMICOLON   // ;
	DOT         // .

	// ALL and the following are Genji SQL Keywords
	ADD_KEYWORD
	ALTER
	AS
	ASC
	BEGIN
	BY
	CAST
	COMMIT
	CREATE
	DEFAULT
	DELETE
	DESC
	DISTINCT
	DROP
	EXISTS
	EXPLAIN
	FIELD
	FROM
	GROUP
	IF
	INDEX
	INSERT
	INTO
	KEY
	LIMIT
	NOT
	OFFSET
	ON
	ONLY
	ORDER
	PRECISION
	PRIMARY
	READ
	REINDEX
	RENAME
	RETURNING
	ROLLBACK
	SELECT
	SET
	TABLE
	TO
	TRANSACTION
	UNIQUE
	UNSET
	UPDATE
	VALUES
	WHERE
	WRITE

	// Aliases
	TYPEARRAY
	TYPEBIGINT
	TYPEBLOB
	TYPEBOOL
	TYPEBYTES
	TYPECHARACTER
	TYPEDOCUMENT
	TYPEDOUBLE
	TYPEINT
	TYPEINT2
	TYPEINT8
	TYPEINTEGER
	TYPEMEDIUMINT
	TYPESMALLINT
	TYPETEXT
	TYPETINYINT
	TYPEREAL
	TYPEVARCHAR
)

These are a comprehensive list of Genji SQL language tokens.

func (Token) IsOperator

func (tok Token) IsOperator() bool

IsOperator returns true for operator tokens.

func (Token) Precedence

func (tok Token) Precedence() int

Precedence returns the operator precedence of the binary operator token.

func (Token) String

func (tok Token) String() string

String returns the string representation of the token.

Jump to

Keyboard shortcuts

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