lexer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lexer provides tokenization for SQLite SQL statements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexer

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

Lexer represents a lexical scanner for SQLite SQL.

func New

func New(input string) *Lexer

New creates a new Lexer for the input string.

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken returns the next token from the input.

type Token

type Token struct {
	Type    TokenType
	Literal string
	Line    int
	Column  int
}

Token represents a lexical token.

type TokenType

type TokenType string

TokenType represents the type of token

const (
	// Special tokens
	ILLEGAL TokenType = "ILLEGAL" // Token that we don't know about
	EOF     TokenType = "EOF"     // End of file
	WS      TokenType = "WS"      // Whitespace

	// Keywords
	SELECT  TokenType = "SELECT"
	FROM    TokenType = "FROM"
	WHERE   TokenType = "WHERE"
	INSERT  TokenType = "INSERT"
	INTO    TokenType = "INTO"
	VALUES  TokenType = "VALUES"
	UPDATE  TokenType = "UPDATE"
	SET     TokenType = "SET"
	DELETE  TokenType = "DELETE"
	CREATE  TokenType = "CREATE"
	TABLE   TokenType = "TABLE"
	INDEX   TokenType = "INDEX"
	DROP    TokenType = "DROP"
	NULL    TokenType = "NULL"
	NOT     TokenType = "NOT"
	IS      TokenType = "IS"
	AND     TokenType = "AND"
	OR      TokenType = "OR"
	TRUE    TokenType = "TRUE"
	FALSE   TokenType = "FALSE"
	IN      TokenType = "IN"
	BETWEEN TokenType = "BETWEEN"
	LIKE    TokenType = "LIKE"
	AS      TokenType = "AS"
	ORDER   TokenType = "ORDER"
	BY      TokenType = "BY"
	GROUP   TokenType = "GROUP"
	HAVING  TokenType = "HAVING"
	LIMIT   TokenType = "LIMIT"
	OFFSET  TokenType = "OFFSET"
	JOIN    TokenType = "JOIN"
	LEFT    TokenType = "LEFT"
	RIGHT   TokenType = "RIGHT"
	INNER   TokenType = "INNER"
	OUTER   TokenType = "OUTER"
	ON      TokenType = "ON"
	ASC     TokenType = "ASC"
	DESC    TokenType = "DESC"

	// Identifiers and literals
	IDENT      TokenType = "IDENT"      // table_name, column_name, etc.
	STRING     TokenType = "STRING"     // "foo", 'bar'
	INTEGER    TokenType = "INTEGER"    // 42, 1234
	FLOAT      TokenType = "FLOAT"      // 3.14, 2.5
	BLOB       TokenType = "BLOB"       // X'53514C697465'
	BIND_PARAM TokenType = "BIND_PARAM" // ?1, :name, @param

	// Operators
	ASTERISK     TokenType = "ASTERISK"     // *
	COMMA        TokenType = "COMMA"        // ,
	DOT          TokenType = "DOT"          // .
	LPAREN       TokenType = "LPAREN"       // (
	RPAREN       TokenType = "RPAREN"       // )
	EQ           TokenType = "EQ"           // =
	NE           TokenType = "NE"           // !=, <>
	LT           TokenType = "LT"           // <
	GT           TokenType = "GT"           // >
	LE           TokenType = "LE"           // <=
	GE           TokenType = "GE"           // >=
	PLUS         TokenType = "PLUS"         // +
	MINUS        TokenType = "MINUS"        // -
	SLASH        TokenType = "SLASH"        // /
	PERCENT      TokenType = "PERCENT"      // %
	SEMICOLON    TokenType = "SEMICOLON"    // ;
	SINGLE_QUOTE TokenType = "SINGLE_QUOTE" // '
	DOUBLE_QUOTE TokenType = "DOUBLE_QUOTE" // "
	BACKTICK     TokenType = "BACKTICK"     // `
	LBRACKET     TokenType = "LBRACKET"     // [
	RBRACKET     TokenType = "RBRACKET"     // ]
)

Define token types

Jump to

Keyboard shortcuts

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