dialect

package
v0.35.17 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dialect provides canonical type-to-language mapping via dialect registries. A dialect maps canonical type names (e.g., "string", "uuid", "datetime") to language-specific spellings (e.g., Go's "string", Postgres's "UUID").

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownDialect is returned when resolving a type against a dialect that
	// does not exist in the registry.
	ErrUnknownDialect = errors.New("unknown dialect")

	// ErrUnmappedType is returned when a canonical type has no mapping in the
	// requested dialect.
	ErrUnmappedType = errors.New("unmapped canonical type")
)

Sentinel errors for dialect resolution.

Functions

func UserDialectsDir

func UserDialectsDir() (string, error)

UserDialectsDir returns the user-global dialect directory path. This is <XDG_DATA_HOME>/tag/dialects/ (typically ~/.local/share/tag/dialects/).

Types

type Dialect

type Dialect struct {
	Name        string            `yaml:"name"`
	Description string            `yaml:"description,omitempty"`
	Types       map[string]string `yaml:"types"`
}

Dialect represents a single dialect with its type mappings.

type Registry

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

Registry holds a collection of named dialects and resolves canonical types to dialect-specific types.

func LoadDefaults

func LoadDefaults() (*Registry, error)

LoadDefaults creates a registry populated with only the built-in dialects.

func LoadForTemplate

func LoadForTemplate(templateRoot, dialectsDirName string) (*Registry, error)

LoadForTemplate loads dialects using three-tier resolution for a given template directory: built-in → user-global → template-local (_dialects/). The dialectsDir constant must be passed in to avoid a dependency on internal/types from this leaf package.

func LoadWithOverrides

func LoadWithOverrides(userDir, templateDir string) (*Registry, error)

LoadWithOverrides creates a registry using three-tier loading:

  1. Built-in dialects (embedded YAML files)
  2. User-global dialects from userDir (if non-empty and directory exists)
  3. Template-local dialects from templateDir (if non-empty and directory exists)

Later tiers override individual type mappings via deep merge. Empty directory paths are silently skipped.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty dialect registry.

func (*Registry) Get

func (r *Registry) Get(name string) *Dialect

Get returns the dialect with the given name, or nil if it does not exist. The returned Dialect must not be modified by callers.

func (*Registry) Load

func (r *Registry) Load(data []byte) error

Load parses a single YAML dialect definition and merges it into the registry. If a dialect with the same name already exists, the type mappings are deep-merged (individual type keys from the new definition override existing ones).

func (*Registry) LoadDir

func (r *Registry) LoadDir(dir string) error

LoadDir loads all *.yaml files from a directory on disk into the registry. Files are loaded in lexical order for deterministic results. Returns nil if the directory does not exist.

func (*Registry) LoadFS

func (r *Registry) LoadFS(fsys fs.FS, dir string) error

LoadFS loads all *.yaml files from a directory within an fs.FS into the registry. Files are loaded in lexical order for deterministic results. Uses forward-slash path joining as required by the fs.FS interface.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the sorted names of all dialects in the registry.

func (*Registry) Resolve

func (r *Registry) Resolve(canonicalType, dialectName string) (string, error)

Resolve looks up the target type for a canonical type name in the given dialect. Returns ErrUnknownDialect if the dialect does not exist. Returns ErrUnmappedType if the canonical type has no mapping in the dialect.

Jump to

Keyboard shortcuts

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