rules

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package rules implements the structural rule checks R1–R9. This file is R1 (slot legality + node completeness), which runs in phase P2's pipeline position; catalog-free and catalog-dependent rule passes (R2–R9) arrive in P3. See docs/design/02-rendering.md §4 and 03-structural-rules.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLexical

CheckLexical runs the catalog-free rule pass: R6 (anchored clauses) and R9 (parameter discipline). As a side effect it classifies each parameter's optionality (consumed by codegen). See docs/design/03-structural-rules.md §3–4.

func CheckR1

CheckR1 validates that every fragment is one complete AST node in its slot and that every rendering parses as a single DML statement. rs must come from ast.Renderings (maximal first).

Order matters for diagnostics quality: fragment-local probes run first (they pinpoint the offending fragment), then whole-rendering parses, then AST-membership consistency checks on the maximal tree.

func CheckResolved

func CheckResolved(profile dialect.LexerProfile, q *template.QueryTemplate, maxR ast.Rendering,
	maxTree dialect.Tree, cat *cache.Catalog) []diagnostics.Diagnostic

CheckResolved runs the catalog-dependent rule pass on the parsed maximal rendering: R3 (resolution-based guarded scope), R2's star expansion, ambiguity detection, and the planner-sensitive combination table. See docs/design/03-structural-rules.md §6–7.

Qualified column references are resolved innermost-first (design 03 §6): a qualifier introduced by an enclosing subquery scope (ColRef.ScopeAliases) shadows a same-named top-level relation, so the reference binds locally and the top-level guard is not re-derived for it; a correlated qualified reference (qualifier absent from every enclosing subquery FROM) is still checked. UNqualified references inside subquery scopes remain skipped — resolving a bare column against nested scopes is not modeled — with the per-shape EXPLAIN property test as the mechanical backstop.

func CheckTypeAgreement

func CheckTypeAgreement(q *template.QueryTemplate, rs []ast.Rendering,
	descs []dialect.Desc) []diagnostics.Diagnostic

CheckTypeAgreement verifies the cross-rendering obligations of design 04 §5: every rendering agrees with the maximal one on result columns (SQLETCH210) and every template parameter has a single type across all renderings that bind it (SQLETCH211). descs[i] must correspond to rs[i].

Types

type ParamType

type ParamType struct {
	Name string
	Type dialect.TypeRef
}

ParamType is one template parameter's pinned type (premise P1), ordered like q.ParamOrder.

func ResolveParamTypes

func ResolveParamTypes(q *template.QueryTemplate, rs []ast.Rendering,
	descs []dialect.Desc) ([]ParamType, []diagnostics.Diagnostic)

ResolveParamTypes unifies each template parameter's type across all renderings (they must agree — SQLETCH211) and returns the pinned types in q.ParamOrder.

Jump to

Keyboard shortcuts

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