lexer

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lexer implements a small, allocation-free SQL lexer for the interpolation package. It only recognizes lexical regions that matter when locating placeholders: quoted strings and identifiers, comments and the placeholders themselves. It does not parse SQL grammar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct {
	Placeholder           PlaceholderStyle
	HashComment           bool
	HashCommentNeedsSpace bool
	DashCommentNeedsSpace bool
	SlashSlashComment     bool
	BraceComment          bool
	LineCommentEndsOnCR   bool
	BlockCommentNested    bool
	ExecutableComment     bool
	BackslashEscape       bool
	BacktickIdent         bool
	BracketIdent          bool
	PGStyle               bool
	OracleAltQuote        bool
}

Dialect describes the lexical rules that vary between SQL flavors.

type PlaceholderStyle

type PlaceholderStyle int

PlaceholderStyle selects the parameter syntax recognized by the scanner.

const (
	// NoPlaceholder disables placeholder recognition.
	NoPlaceholder PlaceholderStyle = iota
	// QuestionMark recognizes sequential "?" parameters.
	QuestionMark
	// DollarNumber recognizes numbered "$1" parameters.
	DollarNumber
	// AtNumber recognizes numbered "@p1" parameters.
	AtNumber
	// ColonNumber recognizes numbered ":1" parameters.
	ColonNumber
)

type Scanner

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

Scanner walks a SQL query once and emits tokens covering the whole input.

func New

func New(sql string, d Dialect) *Scanner

New creates a scanner for sql using the rules in d.

func (*Scanner) Scan

func (s *Scanner) Scan() (Token, bool)

Scan returns the next token. The second return value is false when the entire query has been consumed.

type Token

type Token struct {
	Type       TokenType
	Start, End int
}

Token is a half-open byte range [Start, End) of the original SQL query.

type TokenType

type TokenType int

TokenType identifies a lexical region in a SQL query.

const (
	// Text is an ordinary part of the query.
	Text TokenType = iota
	// Quoted is a string literal, quoted identifier, dollar-quoted string or
	// another region in which placeholders must not be interpreted.
	Quoted
	// Comment is a line or block comment.
	Comment
	// Placeholder is a parameter to be replaced by a value.
	Placeholder
)

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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