Help us shape the future of Go! Take the 2026 Go Developer Survey

chsql

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package chsql is the ClickHouse SQL lexer that the query guard and the SQL wrappers share. It follows the token rules of the ClickHouse 26.3 lexer (src/Parsers/Lexer.cpp) for every state that can hide a quote, a comment or a keyword: quoted strings and identifiers with backslash escapes and doubled quotes, heredocs, Unicode quotes, nested block comments, line comments, UTF-8 whitespace and numbers with an exponent sign. Text that the server lexer turns into an error token fails Tokenize, so no caller scans past it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimTerminalSemicolon

func TrimTerminalSemicolon(s string) (string, error)

TrimTerminalSemicolon strips one terminal ';' and the whitespace around it, outside quotes and comments. It refuses a second statement and any text, a comment included, after the semicolon.

Types

type Token

type Token struct {
	Kind  TokenKind
	Text  string
	Upper string // Text in upper case, set for Word tokens only
	Depth int    // nesting depth of (), [] and {} at the token; an opening bracket counts itself
	Pos   int    // byte offset of Text in the input
}

func Tokenize

func Tokenize(s string) ([]Token, error)

Tokenize splits s into tokens. The tokens cover s without gaps, so joining their Text gives s back. It fails on an unclosed quote or block comment, or on any byte sequence the ClickHouse lexer rejects.

type TokenKind

type TokenKind int
const (
	Word TokenKind = iota
	QuotedIdent
	String
	Number
	Punct
	Comment
	Space
)

Jump to

Keyboard shortcuts

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