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 ¶
- Variables
- func UserDialectsDir() (string, error)
- type Dialect
- type Registry
- func (r *Registry) Get(name string) *Dialect
- func (r *Registry) Load(data []byte) error
- func (r *Registry) LoadDir(dir string) error
- func (r *Registry) LoadFS(fsys fs.FS, dir string) error
- func (r *Registry) Names() []string
- func (r *Registry) Resolve(canonicalType, dialectName string) (string, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
LoadDefaults creates a registry populated with only the built-in dialects.
func LoadForTemplate ¶
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 ¶
LoadWithOverrides creates a registry using three-tier loading:
- Built-in dialects (embedded YAML files)
- User-global dialects from userDir (if non-empty and directory exists)
- 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 (*Registry) Get ¶
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 ¶
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 ¶
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 ¶
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.