compilers

package
v0.0.0-...-d4700bc Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package compilers defines the contract between spec compilers and the engine: a Compiler lowers source documents of its formats into an ir.Document plus diagnostics, purely and reentrantly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler interface {
	Formats() []SourceFormat
	Compile(ctx context.Context, sources []Source, opts Options) (*ir.Document, []ir.Diagnostic, error)
}

Compiler lowers source documents into the IR. Implementations must be pure: no package-level mutable state, no writes to stderr; spec problems are returned as ir.Diagnostic values and the error return is reserved for I/O-level and programmer errors.

type Options

type Options struct {
	FormatOptions any
}

Options carries per-compile configuration. FormatOptions is the compiler-specific options value; each compiler documents the concrete type it accepts and treats nil as defaults.

type Registry

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

Registry maps source formats to compilers. It is a plain instance — there is no package-level default and no init()-time self-registration; the engine composes its registry explicitly.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Formats

func (r *Registry) Formats() []SourceFormat

Formats lists every registered format, sorted for stable display.

func (*Registry) Lookup

func (r *Registry) Lookup(format SourceFormat) (Compiler, bool)

Lookup returns the compiler registered for format.

func (*Registry) Register

func (r *Registry) Register(c Compiler) error

Register adds c under every format it reports. It fails if any format is already claimed; on failure nothing is registered.

type Source

type Source struct {
	Path string
	Data []byte
}

Source is one pre-read input document. Compilers perform no file I/O; the caller loads bytes so compilation stays pure and reentrant.

type SourceFormat

type SourceFormat struct {
	Name    string // "openapi", "swagger", "typespec", "smithy", ...
	Version string // "3.0", "3.1", "2.0", ...
}

SourceFormat identifies one spec dialect a compiler accepts.

func (SourceFormat) String

func (f SourceFormat) String() string

String renders the canonical "name@version" form used in diagnostics and registry errors.

Directories

Path Synopsis
Package openapi lowers OpenAPI 3.0/3.1/3.2 documents into the Morphic IR.
Package openapi lowers OpenAPI 3.0/3.1/3.2 documents into the Morphic IR.

Jump to

Keyboard shortcuts

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