110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package compiler
|
|
|
|
import (
|
|
"go/ast"
|
|
|
|
"gamertan.com/sandwich-hime/internal/version"
|
|
)
|
|
|
|
// CompilerVersion mirrors the release-injected compiler version for callers
|
|
// that need to display provenance alongside generated output.
|
|
var CompilerVersion = version.Compiler
|
|
|
|
// RuntimeABI is the generated-code/runtime compatibility boundary for v1.
|
|
const RuntimeABI = version.RuntimeABI
|
|
|
|
const (
|
|
runtimeImportPath = "gamertan.com/sandwich-hime/sando"
|
|
generatedPrefix = "// Code generated by himesan; DO NOT EDIT."
|
|
)
|
|
|
|
// Context identifies the escaping context assigned to a renderer operation.
|
|
type Context string
|
|
|
|
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 nodeKind uint8
|
|
|
|
const (
|
|
nodeText nodeKind = iota
|
|
nodeStatement
|
|
nodeExpression
|
|
nodeComponent
|
|
nodeComment
|
|
)
|
|
|
|
// rendererNode is the context-annotated renderer IR. Context is assigned by
|
|
// analyzeContexts before any backend is allowed to consume the IR.
|
|
type rendererNode struct {
|
|
Kind nodeKind
|
|
Text string
|
|
Context Context
|
|
Pos sourcePosition
|
|
}
|
|
|
|
type sourcePosition struct {
|
|
Offset int
|
|
Line int
|
|
Column int
|
|
}
|
|
|
|
type sourceFile struct {
|
|
Path string
|
|
Mapping string
|
|
Package string
|
|
Name string
|
|
TypeParams string
|
|
Params string
|
|
Imports []sourceImport
|
|
Nodes []rendererNode
|
|
Source []byte
|
|
HeaderEnd int
|
|
AST *ast.File
|
|
}
|
|
|
|
type sourceImport struct {
|
|
Alias string
|
|
Path string
|
|
}
|
|
|
|
// CompiledFile is a fully validated generated output held in memory.
|
|
type CompiledFile struct {
|
|
SourcePath string
|
|
OutputPath string
|
|
Package string
|
|
Component string
|
|
Digest string
|
|
Code []byte
|
|
source *sourceFile
|
|
}
|
|
|
|
// FileResult describes one source/output pair processed by Generate or Check.
|
|
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"`
|
|
}
|
|
|
|
// Result is returned even when an operation reports diagnostics.
|
|
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"`
|
|
}
|