parser

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package parser provides a recursive descent SQL parser that converts tokens into an Abstract Syntax Tree (AST). It supports comprehensive SQL features including SELECT, INSERT, UPDATE, DELETE, DDL operations, Common Table Expressions (CTEs), set operations (UNION, EXCEPT, INTERSECT), and window functions.

Phase 2 Features (v1.2.0+):

  • Common Table Expressions (WITH clause) with recursive support
  • Set operations: UNION, UNION ALL, EXCEPT, INTERSECT
  • Multiple CTE definitions in single query
  • CTE column specifications
  • Left-associative set operation parsing
  • Integration of CTEs with set operations

Phase 2.5 Features (v1.3.0+):

  • Window functions with OVER clause support
  • PARTITION BY and ORDER BY in window specifications
  • Window frame clauses (ROWS/RANGE with bounds)
  • Ranking functions: ROW_NUMBER(), RANK(), DENSE_RANK(), NTILE()
  • Analytic functions: LAG(), LEAD(), FIRST_VALUE(), LAST_VALUE()
  • Function call parsing with parentheses and arguments
  • Integration with existing SELECT statement parsing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTokensForParser added in v1.4.0

func ConvertTokensForParser(tokens []models.TokenWithSpan) ([]token.Token, error)

ConvertTokensForParser is a convenient function that creates a converter and converts tokens This maintains backward compatibility with existing CLI code

Types

type ConversionResult added in v1.4.0

type ConversionResult struct {
	Tokens          []token.Token
	PositionMapping []TokenPosition // Maps parser token index to original position
}

ConversionResult contains the converted tokens and any position mappings

func ConvertTokensWithPositions added in v1.4.0

func ConvertTokensWithPositions(tokens []models.TokenWithSpan) (*ConversionResult, error)

ConvertTokensWithPositions provides both tokens and position mapping for enhanced error reporting

type Parser

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

Parser represents a SQL parser

func NewParser

func NewParser() *Parser

NewParser creates a new parser

func (*Parser) Parse

func (p *Parser) Parse(tokens []token.Token) (*ast.AST, error)

Parse parses the tokens into an AST

func (*Parser) Release

func (p *Parser) Release()

Release releases any resources held by the parser

type TokenConverter added in v1.4.0

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

TokenConverter provides centralized, optimized token conversion from tokenizer output (models.TokenWithSpan) to parser input (token.Token)

func NewTokenConverter added in v1.4.0

func NewTokenConverter() *TokenConverter

NewTokenConverter creates an optimized token converter

func (*TokenConverter) Convert added in v1.4.0

func (tc *TokenConverter) Convert(tokens []models.TokenWithSpan) (*ConversionResult, error)

Convert converts tokenizer tokens to parser tokens with position tracking

type TokenPosition added in v1.4.0

type TokenPosition struct {
	OriginalIndex int                   // Index in original token slice
	Start         models.Location       // Original start position
	End           models.Location       // Original end position
	SourceToken   *models.TokenWithSpan // Reference to original token for error reporting
}

TokenPosition maps a parser token back to its original source position

Jump to

Keyboard shortcuts

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