compiler

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package compiler implements the Hime-san .sando compiler.

Index

Constants

View Source
const RuntimeABI = version.RuntimeABI

RuntimeABI is the generated-code/runtime compatibility boundary for v1.

Variables

View Source
var CompilerVersion = version.Compiler

CompilerVersion mirrors the release-injected compiler version for callers that need to display provenance alongside generated output.

Functions

func Compile

func Compile(path string, source []byte) (CompiledFile, []Diagnostic)

Compile parses, context-checks, and formats one .sando source entirely in memory. It never reads project metadata, writes a file, or executes Go code.

Types

type AnalysisImport

type AnalysisImport struct {
	Alias string `json:"alias,omitempty"`
	Path  string `json:"path"`
}

AnalysisImport describes one import already present in a .sando header.

type AnalysisRegion

type AnalysisRegion struct {
	Kind    AnalysisRegionKind `json:"kind"`
	Text    string             `json:"text,omitempty"`
	Context Context            `json:"context,omitempty"`
	Offset  int                `json:"offset"`
	Length  int                `json:"length"`
	Line    int                `json:"line"`
	Column  int                `json:"column"`
}

AnalysisRegion describes a Hime-san tag body using zero-based byte offsets. Line and Column retain the compiler's one-based byte-coordinate convention; protocol adapters convert them to UTF-16 where required.

type AnalysisRegionKind

type AnalysisRegionKind string

AnalysisRegionKind identifies an author-visible template region.

const (
	AnalysisStatement  AnalysisRegionKind = "statement"
	AnalysisExpression AnalysisRegionKind = "expression"
	AnalysisComponent  AnalysisRegionKind = "component"
	AnalysisComment    AnalysisRegionKind = "comment"
)

type CompiledFile

type CompiledFile struct {
	SourcePath string
	OutputPath string
	Package    string
	Component  string
	Digest     string
	Code       []byte
	// contains filtered or unexported fields
}

CompiledFile is a fully validated generated output held in memory.

type Context

type Context string

Context identifies the escaping context assigned to a renderer operation.

const (
	ContextHTMLText Context = "html-text"
	ContextRCDATA   Context = "rcdata"
	ContextAttr     Context = "quoted-attribute"
	ContextURL      Context = "url-attribute"
	ContextJS       Context = "script"
	ContextCSS      Context = "style"
	ContextNone     Context = "none"
)

type Diagnostic

type Diagnostic struct {
	Path     string   `json:"path"`
	Line     int      `json:"line"`
	Column   int      `json:"column"`
	Code     string   `json:"code"`
	Severity Severity `json:"severity"`
	Message  string   `json:"message"`
}

Diagnostic is a stable, machine-readable compiler message. Line and Column are one-based. A diagnostic without a source position uses line and column 1.

func DiscoverSources

func DiscoverSources(ctx context.Context, paths []string) ([]string, []Diagnostic)

DiscoverSources finds .sando sources using the same filesystem, symlink, nested-module, VCS, and vendor boundaries as Generate and Check. It omits generated-output inspection because editor analysis does not own freshness.

func (Diagnostic) Error

func (d Diagnostic) Error() string

type DiagnosticsError

type DiagnosticsError struct {
	Diagnostics []Diagnostic
}

DiagnosticsError reports one or more error diagnostics.

func (*DiagnosticsError) Error

func (e *DiagnosticsError) Error() string

type DocumentAnalysis

type DocumentAnalysis struct {
	Path            string           `json:"path"`
	Package         string           `json:"package,omitempty"`
	Component       string           `json:"component,omitempty"`
	TypeParams      string           `json:"type_params,omitempty"`
	Params          string           `json:"params,omitempty"`
	Signature       string           `json:"signature,omitempty"`
	ComponentOffset int              `json:"component_offset,omitempty"`
	ComponentLine   int              `json:"component_line,omitempty"`
	ComponentColumn int              `json:"component_column,omitempty"`
	Imports         []AnalysisImport `json:"imports,omitempty"`
	Regions         []AnalysisRegion `json:"regions,omitempty"`
	Diagnostics     []Diagnostic     `json:"diagnostics,omitempty"`
}

DocumentAnalysis is the compiler-owned semantic description consumed by read-only tools such as the language server.

func AnalyzeSources

func AnalyzeSources(ctx context.Context, inputs []SourceInput) []DocumentAnalysis

AnalyzeSources applies the normal parser, HTML-context analyzer, trust audit, backend validation, duplicate-component checks, and statically knowable cycle checks to an in-memory source set. It performs no I/O.

type FileResult

type FileResult struct {
	SourcePath string `json:"source_path"`
	OutputPath string `json:"output_path"`
	Changed    bool   `json:"changed"`
	Stale      bool   `json:"stale"`
	Missing    bool   `json:"missing"`
}

FileResult describes one source/output pair processed by Generate or Check.

type Result

type Result struct {
	Files       []FileResult `json:"files"`
	Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
	Discovered  int          `json:"discovered"`
	Changed     int          `json:"changed"`
	Unchanged   int          `json:"unchanged"`
	Stale       int          `json:"stale"`
	Missing     int          `json:"missing"`
}

Result is returned even when an operation reports diagnostics.

func Check

func Check(ctx context.Context, paths []string) (Result, error)

Check validates sources and reports missing or stale generated output without writing to the filesystem. Warnings, including trusted-value audit findings, do not cause Check to fail by themselves.

func Generate

func Generate(ctx context.Context, paths []string) (Result, error)

Generate compiles all discovered .sando files in memory, then atomically replaces only changed, Hime-san-owned .sando.go outputs. Any parse, context, format, cycle, or ownership error prevents every output write.

type Severity

type Severity string

Severity describes the impact of a diagnostic.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

type SourceInput

type SourceInput struct {
	Path   string
	Source []byte
}

SourceInput supplies one in-memory .sando document for editor analysis.

Jump to

Keyboard shortcuts

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