analysis

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package analysis derives deterministic semantic indexes from validated schemas. It assigns stable IDs, resolves QName references, and enforces cycle invariants.

Index

Constants

View Source
const (
	// InvalidTypeID represents an unassigned type ID.
	InvalidTypeID ids.TypeID = ids.InvalidTypeID
	// InvalidElemID represents an unassigned element ID.
	InvalidElemID ids.ElemID = ids.InvalidElemID
	// InvalidAttrID represents an unassigned attribute ID.
	InvalidAttrID ids.AttrID = ids.InvalidAttrID
)

Variables

This section is empty.

Functions

func DetectCycles

func DetectCycles(schema *parser.Schema) error

DetectCycles validates that type derivation, group refs, attribute group refs, and substitution groups are acyclic.

func RequireResolved

func RequireResolved(schema *parser.Schema) error

RequireResolved ensures the schema is placeholder-free.

func SortedGlobalDecls

func SortedGlobalDecls(decls []parser.GlobalDecl) []parser.GlobalDecl

SortedGlobalDecls returns a sorted copy of global declarations.

func SortedQNames

func SortedQNames[V any](m map[types.QName]V) []types.QName

SortedQNames returns QNames in deterministic order (namespace, local).

Types

type AncestorIndex

type AncestorIndex struct {
	IDs     []ids.TypeID
	Masks   []types.DerivationMethod
	Offsets []uint32
	Lengths []uint32
}

AncestorIndex stores ancestor chains and cumulative derivation masks by TypeID.

func BuildAncestors

func BuildAncestors(schema *parser.Schema, registry *Registry) (*AncestorIndex, error)

BuildAncestors computes ancestor chains for all types in registry order. Built-in base types terminate a chain and are not included.

type AttributeEntry

type AttributeEntry struct {
	Decl   *types.AttributeDecl
	QName  types.QName
	ID     ids.AttrID
	Global bool
}

AttributeEntry records an attribute ID assignment in traversal order.

type ElementEntry

type ElementEntry struct {
	Decl   *types.ElementDecl
	QName  types.QName
	ID     ids.ElemID
	Global bool
}

ElementEntry records an element ID assignment in traversal order.

type Registry

type Registry struct {
	Types      map[types.QName]ids.TypeID
	Elements   map[types.QName]ids.ElemID
	Attributes map[types.QName]ids.AttrID

	TypeOrder      []TypeEntry
	ElementOrder   []ElementEntry
	AttributeOrder []AttributeEntry
	// contains filtered or unexported fields
}

Registry holds deterministic ID assignments for schema components.

func AssignIDs

func AssignIDs(schema *parser.Schema) (*Registry, error)

AssignIDs walks the parsed schema in deterministic order and assigns IDs.

func (*Registry) LookupAnonymousTypeID

func (r *Registry) LookupAnonymousTypeID(typ types.Type) (ids.TypeID, bool)

LookupAnonymousTypeID resolves an anonymous type definition to its assigned ID.

func (*Registry) LookupLocalAttributeID

func (r *Registry) LookupLocalAttributeID(decl *types.AttributeDecl) (ids.AttrID, bool)

LookupLocalAttributeID resolves a local attribute declaration to its assigned ID.

func (*Registry) LookupLocalElementID

func (r *Registry) LookupLocalElementID(decl *types.ElementDecl) (ids.ElemID, bool)

LookupLocalElementID resolves a local element declaration to its assigned ID.

type ResolvedReferences

type ResolvedReferences struct {
	ElementRefs   map[types.QName]ids.ElemID
	AttributeRefs map[types.QName]ids.AttrID
	GroupRefs     map[types.QName]types.QName
}

ResolvedReferences records resolved references without mutating the parsed schema.

func ResolveReferences

func ResolveReferences(schema *parser.Schema, registry *Registry) (*ResolvedReferences, error)

ResolveReferences validates and resolves QName references in the parsed schema.

type TypeEntry

type TypeEntry struct {
	Type   types.Type
	QName  types.QName
	ID     ids.TypeID
	Global bool
}

TypeEntry records a type ID assignment in traversal order.

Jump to

Keyboard shortcuts

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