parser

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package parser contains the internal PostgreSQL parsing boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error is a privacy-safe failure from the internal parser boundary. It never stores or unwraps the backend error because that diagnostic can quote SQL.

func (*Error) Category

func (e *Error) Category() FailureCategory

Category returns the bounded parser failure category.

func (*Error) Error

func (*Error) Error() string

Error returns a constant message that does not disclose parser input.

type FailureCategory

type FailureCategory string

FailureCategory identifies a bounded parser failure class.

const FailureSyntax FailureCategory = "syntax"

FailureSyntax indicates that PostgreSQL rejected the input syntax.

type Field

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

Field is an immutable named value on a Node. Its state stays private so a parsed tree cannot be changed through values returned to another package.

func (Field) Name

func (f Field) Name() string

Name returns the parser-neutral field name.

func (Field) Value

func (f Field) Value() Value

Value returns the field value.

type Kind

type Kind string

Kind identifies a parser-neutral PostgreSQL AST node type. It deliberately avoids backend-generated enums so callers do not depend on pg_query types.

type Node

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

Node is an immutable parser-neutral PostgreSQL AST node. Accessors return snapshots for slice-backed data; child nodes are safe to share because all their state is private and has no mutating API.

func StatementSequence

func StatementSequence(result *Result) []*Node

StatementSequence returns top-level statements and their statement-bearing CTEs in deterministic root-first, depth-first declaration order. A new slice is built for every call, so consumers cannot mutate Result state.

func (*Node) Field

func (n *Node) Field(name string) (Value, bool)

Field returns a named field value.

func (*Node) Fields

func (n *Node) Fields() []Field

Fields returns a snapshot of the node fields in schema declaration order. Declaration order makes structural traversal reproducible across calls.

func (*Node) Kind

func (n *Node) Kind() Kind

Kind returns the PostgreSQL AST node kind.

type Result

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

Result is an immutable parser-neutral PostgreSQL parse result. It owns the top-level statement order produced by PostgreSQL.

func Parse

func Parse(sql string) (*Result, error)

Parse parses complete SQL input with the PostgreSQL grammar and immediately converts the backend tree into package-owned immutable values. Raw backend errors are reduced to a bounded, privacy-safe category before returning.

func (*Result) Statements

func (r *Result) Statements() []*Node

Statements returns a snapshot of the top-level statements in input order.

type Value

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

Value is an immutable parser-neutral scalar, node, or list. The tagged union keeps protobuf reflection values from crossing the parser boundary.

func (Value) Bool

func (v Value) Bool() (bool, bool)

Bool returns the stored boolean.

func (Value) Bytes

func (v Value) Bytes() ([]byte, bool)

Bytes returns a snapshot of the stored bytes so callers cannot mutate the parsed tree through a shared backing array.

func (Value) Enum

func (v Value) Enum() (string, bool)

Enum returns the stored symbolic enum value.

func (Value) Float

func (v Value) Float() (float64, bool)

Float returns the stored floating-point number.

func (Value) Int

func (v Value) Int() (int64, bool)

Int returns the stored signed integer.

func (Value) Kind

func (v Value) Kind() ValueKind

Kind returns the stored value kind.

func (Value) List

func (v Value) List() ([]Value, bool)

List returns a snapshot of the stored list so callers can reorder or replace returned values without changing the parsed tree.

func (Value) Node

func (v Value) Node() (*Node, bool)

Node returns the stored node.

func (Value) String

func (v Value) String() (string, bool)

String returns the stored string.

func (Value) Uint

func (v Value) Uint() (uint64, bool)

Uint returns the stored unsigned integer.

type ValueKind

type ValueKind uint8

ValueKind identifies the data stored in a Value.

const (
	ValueInvalid ValueKind = iota
	ValueBool
	ValueInt
	ValueUint
	ValueFloat
	ValueString
	ValueBytes
	ValueEnum
	ValueNode
	ValueList
)

Parser-neutral value kinds.

Jump to

Keyboard shortcuts

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