models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keyword

type Keyword struct {
	Word     string // The actual keyword text
	Reserved bool   // Whether this is a reserved keyword
}

Keyword represents a lexical keyword with its properties

type Location

type Location struct {
	Line   int
	Column int
}

Location represents a position in the source code using 1-based indexing. Both Line and Column are 1-based to match SQL standards.

type Span

type Span struct {
	Start Location
	End   Location
}

Span represents a range in the source code

func EmptySpan

func EmptySpan() Span

Empty returns an empty span

func NewSpan

func NewSpan(start, end Location) Span

NewSpan creates a new span from start to end locations

type Token

type Token struct {
	Type  TokenType
	Value string
	Word  *Word // For TokenTypeWord
	Long  bool  // For TokenTypeNumber to indicate if it's a long number
	Quote rune  // For quoted strings and identifiers
}

Token represents a SQL token with its value and metadata

func NewToken

func NewToken(tokenType TokenType, value string) Token

NewToken creates a new Token with the given type and value

type TokenType

type TokenType int

TokenType represents the type of a SQL token

const (
	// Basic token types
	TokenTypeEOF TokenType = iota
	TokenTypeWord
	TokenTypeNumber
	TokenTypeChar
	TokenTypeSingleQuotedString
	TokenTypeDoubleQuotedString
	TokenTypeTripleSingleQuotedString
	TokenTypeTripleDoubleQuotedString
	TokenTypeDollarQuotedString
	TokenTypeByteStringLiteral
	TokenTypeNationalStringLiteral
	TokenTypeEscapedStringLiteral
	TokenTypeUnicodeStringLiteral
	TokenTypeHexStringLiteral
	TokenTypeWhitespace

	// Operators and punctuation
	TokenTypeComma
	TokenTypeDoubleEq
	TokenTypeEq
	TokenTypeNeq
	TokenTypeLt
	TokenTypeGt
	TokenTypeLtEq
	TokenTypeGtEq
	TokenTypeSpaceship
	TokenTypePlus
	TokenTypeMinus
	TokenTypeMul
	TokenTypeDiv
	TokenTypeDuckIntDiv
	TokenTypeMod
	TokenTypeStringConcat
	TokenTypeLParen
	TokenTypeRParen
	TokenTypePeriod
	TokenTypeColon
	TokenTypeDoubleColon
	TokenTypeAssignment
	TokenTypeSemicolon
	TokenTypeBackslash
	TokenTypeLBracket
	TokenTypeRBracket
	TokenTypeAmpersand

	// Keywords
	TokenTypeKeyword
	TokenTypeSelect
	TokenTypeJoin
	TokenTypeInner
	TokenTypeLeft
	TokenTypeRight
	TokenTypeOuter
	TokenTypeGroup
	TokenTypeHaving
	TokenTypeWhere
	TokenTypeOrder
	TokenTypeLimit
	TokenTypeOffset
	TokenTypeOn
	TokenTypeAnd
	TokenTypeLike
	TokenTypeAsc
	TokenTypeFrom
	TokenTypeBy
	TokenTypeOr
	TokenTypeNot
	TokenTypeIn
	TokenTypeCount
	TokenTypeSum
	TokenTypeAvg
	TokenTypeMin
	TokenTypeMax
	TokenTypeBetween
	TokenTypeIs
	TokenTypeNull
	TokenTypeTrue
	TokenTypeFalse
	TokenTypeDesc
	TokenTypeCase
	TokenTypeWhen
	TokenTypeThen
	TokenTypeElse
	TokenTypeEnd
	TokenTypeAs
	TokenTypeGroupBy
	TokenTypeOrderBy
	TokenTypeLeftJoin
	TokenTypeRightJoin
	TokenTypeInnerJoin
	TokenTypeOuterJoin
	TokenTypePipe
	TokenTypeCaret
	TokenTypeLBrace
	TokenTypeRBrace
	TokenTypeRArrow
	TokenTypeSharp
	TokenTypeTilde
	TokenTypeTildeAsterisk
	TokenTypeExclamationMarkTilde
	TokenTypeExclamationMarkTildeAsterisk
	TokenTypeDoubleTilde
	TokenTypeDoubleTildeAsterisk
	TokenTypeExclamationMarkDoubleTilde
	TokenTypeExclamationMarkDoubleTildeAsterisk
	TokenTypeShiftLeft
	TokenTypeShiftRight
	TokenTypeOverlap
	TokenTypeExclamationMark
	TokenTypeDoubleExclamationMark
	TokenTypeAtSign
	TokenTypeCaretAt
	TokenTypePGSquareRoot
	TokenTypePGCubeRoot
	TokenTypePlaceholder
	TokenTypeArrow
	TokenTypeLongArrow
	TokenTypeHashArrow
	TokenTypeHashLongArrow
	TokenTypeAtArrow
	TokenTypeArrowAt
	TokenTypeHashMinus
	TokenTypeAtQuestion
	TokenTypeAtAt
	TokenTypeQuestion
	TokenTypeQuestionAnd
	TokenTypeQuestionPipe
	TokenTypeCustomBinaryOperator

	// Additional token types referenced in tests
	TokenTypeString
	TokenTypeIdentifier
	TokenTypeOperator
	TokenTypeLeftParen
	TokenTypeRightParen
	TokenTypeDot
)

These constants define the token types used in the SQL tokenizer

type TokenWithSpan

type TokenWithSpan struct {
	Token Token
	Start Location
	End   Location
}

TokenWithSpan represents a token with its location in the source code

func NewEOFToken

func NewEOFToken(pos Location) TokenWithSpan

NewEOFToken creates a new EOF token with span

func NewTokenWithSpan

func NewTokenWithSpan(tokenType TokenType, value string, start, end Location) TokenWithSpan

NewTokenWithSpan creates a new TokenWithSpan with the given type, value, and location

func TokenAtLocation

func TokenAtLocation(token Token, start, end Location) TokenWithSpan

TokenAtLocation creates a new TokenWithSpan from a Token and location

func WrapToken

func WrapToken(token Token) TokenWithSpan

WrapToken wraps a token with an empty location

type TokenizerError

type TokenizerError struct {
	Message  string
	Location Location
}

TokenizerError represents an error during tokenization

func (TokenizerError) Error

func (e TokenizerError) Error() string

type Whitespace

type Whitespace struct {
	Type    WhitespaceType
	Content string // For comments
	Prefix  string // For single line comments
}

Whitespace represents different types of whitespace tokens

type WhitespaceType

type WhitespaceType int

WhitespaceType represents the type of whitespace

const (
	WhitespaceTypeSpace WhitespaceType = iota
	WhitespaceTypeNewline
	WhitespaceTypeTab
	WhitespaceTypeSingleLineComment
	WhitespaceTypeMultiLineComment
)

type Word

type Word struct {
	Value      string   // The actual text value
	QuoteStyle rune     // The quote character used (if quoted)
	Keyword    *Keyword // If this word is a keyword
}

Word represents a keyword or identifier with its properties

Jump to

Keyboard shortcuts

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