scanner

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 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 Chai SQL language.

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

	// IDENT and the following are Chai 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        // `.*
	ELLIPSIS        // ...

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

	AND // AND
	OR  // OR

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

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

	// ALL and the following are Chai SQL Keywords
	ADD_KEYWORD
	ALL
	ALTER
	AS
	ASC
	BEGIN
	BY
	CACHE
	CAST
	CHECK
	COLUMN
	COMMIT
	CONFLICT
	CONSTRAINT
	CREATE
	CYCLE
	DEFAULT
	DELETE
	DESC
	DISTINCT
	DO
	DROP
	EXISTS
	EXPLAIN
	FOR
	FROM
	GROUP
	IF
	IGNORE
	INCREMENT
	INDEX
	INSERT
	INTO
	KEY
	LIMIT
	MAXVALUE
	MINVALUE
	NEXT
	NO
	NOT
	NOTHING
	OFFSET
	ON
	ONLY
	ORDER
	PRECISION
	PRIMARY
	READ
	REINDEX
	RENAME
	REPLACE
	RETURNING
	ROLLBACK
	SELECT
	SEQUENCE
	SET
	START
	TABLE
	TO
	TRANSACTION
	UNION
	UNIQUE
	UNSET
	UPDATE
	VALUE
	VALUES
	WITH
	WHERE
	WRITE

	// Types
	TYPEANY
	TYPEARRAY
	TYPEBIGINT
	TYPEBLOB
	TYPEBOOL
	TYPEBOOLEAN
	TYPEBYTES
	TYPECHARACTER
	TYPEDOUBLE
	TYPEINT
	TYPEINT2
	TYPEINT8
	TYPEINTEGER
	TYPEMEDIUMINT
	TYPEOBJECT
	TYPEREAL
	TYPESMALLINT
	TYPETEXT
	TYPETIMESTAMP
	TYPETINYINT
	TYPEVARCHAR
)

These are a comprehensive list of Chai SQL language tokens.

func AllKeywords

func AllKeywords() []Token

AllKeywords returns all defined tokens corresponding to keywords.

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