Documentation
¶
Index ¶
- func ErrorAt(filename, source string, localOffset, baseOffset int, message string) error
- func ErrorAtPosition(filename, source string, localOffset, baseOffset int, basePos Position, ...) error
- type Annotation
- type AnnotationArg
- type AwaitBinding
- type AwaitNode
- type BinaryExpr
- type BodyContext
- func (c *BodyContext) ErrorAt(offset int, message string) error
- func (c *BodyContext) Filename() string
- func (c *BodyContext) Offset() int
- func (c *BodyContext) ParseEmbedded(fragment Embedded, context string) (Node, *Terminator, error)
- func (c *BodyContext) Position(offset int) Position
- func (c *BodyContext) SetOffset(offset int)
- func (c *BodyContext) Source() string
- type CallExpr
- type ConditionalExpr
- type Declaration
- type Embedded
- type EnumDecl
- type EnumMember
- type Expr
- type ExpressionNode
- type ExternalDecl
- type Field
- type ForNode
- type FormatParser
- type IdentifierExpr
- type IfNode
- type ImportDecl
- type IndexExpr
- type LiteralExpr
- type MemberExpr
- type Module
- type Node
- type PackageDecl
- type Parameter
- type ParseError
- type Position
- type RootDeclaration
- type TemplateDecl
- type Terminator
- type TerminatorKind
- type TypeDecl
- type TypeRef
- type UnaryExpr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Annotation ¶ added in v0.1.16
type Annotation struct {
Pos Position `json:"pos"`
Name string `json:"name"`
Args []AnnotationArg `json:"args,omitempty"`
}
Annotation is one `@name(key: "value")` line attached to the declaration below it. The shared parser owns the grammar; each output format decides which names it accepts, so an unknown name is a generation error rather than a silently ignored line.
func (Annotation) Argument ¶ added in v0.1.16
func (a Annotation) Argument(name string) (AnnotationArg, bool)
Argument returns the value of a named annotation argument.
type AnnotationArg ¶ added in v0.1.16
type AwaitBinding ¶ added in v0.1.16
type AwaitBinding struct {
Pos Position `json:"pos"`
Name string `json:"name"`
Call Expr `json:"call"`
}
AwaitBinding names one asynchronous call whose result the primary subtree reads.
type AwaitNode ¶ added in v0.1.16
type AwaitNode struct {
Kind string `json:"kind"`
Pos Position `json:"pos"`
Context string `json:"context"`
Bindings []AwaitBinding `json:"bindings"`
Primary []Node `json:"primary"`
Fallback []Node `json:"fallback"`
// HasRecover distinguishes a declared but empty recover subtree from an
// omitted one, which keeps the committed fallback instead.
HasRecover bool `json:"hasRecover,omitempty"`
Recover []Node `json:"recover,omitempty"`
ErrorName string `json:"errorName,omitempty"`
ErrorPos Position `json:"errorPos,omitempty"`
}
AwaitNode is one asynchronous boundary. Its bindings run concurrently; the primary subtree reads them, the fallback subtree is emitted while they are pending, and the optional recover subtree replaces the fallback on failure.
How many times the boundary renders is a property of what its bindings name, not of the clause: a binding on a settle-once source produces one render, and a binding on a live source produces one per delivery. The clause says which values the subtree waits for, and the declarations say how those values arrive, so nothing here has to be repeated at the wait site.
type BinaryExpr ¶
type BodyContext ¶
type BodyContext struct {
// contains filtered or unexported fields
}
BodyContext is the shared cursor and control orchestrator for one declaration body. Format parsers must use it instead of owning an independent cursor.
func (*BodyContext) Filename ¶
func (c *BodyContext) Filename() string
func (*BodyContext) Offset ¶
func (c *BodyContext) Offset() int
func (*BodyContext) ParseEmbedded ¶
func (c *BodyContext) ParseEmbedded(fragment Embedded, context string) (Node, *Terminator, error)
ParseEmbedded parses one fragment after the active format parser has found its boundaries. It returns either a shared node or a control terminator.
func (*BodyContext) Position ¶
func (c *BodyContext) Position(offset int) Position
func (*BodyContext) SetOffset ¶
func (c *BodyContext) SetOffset(offset int)
func (*BodyContext) Source ¶
func (c *BodyContext) Source() string
type ConditionalExpr ¶
type Declaration ¶
type Declaration interface {
// contains filtered or unexported methods
}
Declaration is implemented by all root declarations.
type Embedded ¶
Embedded is one brace-delimited template fragment discovered by a format parser. Offsets are file-global byte offsets.
type EnumDecl ¶
type EnumDecl struct {
Kind string `json:"kind"`
Pos Position `json:"pos"`
Name string `json:"name"`
Members []EnumMember `json:"members"`
}
type EnumMember ¶
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr is the shared expression AST embedded by every output format.
func ParseExpression ¶
ParseExpression parses a complete shared template expression.
type ExpressionNode ¶
type ExpressionNode struct {
Kind string `json:"kind"`
Pos Position `json:"pos"`
Context string `json:"context"`
Expression Expr `json:"expression"`
}
func (*ExpressionNode) NodeType ¶
func (n *ExpressionNode) NodeType() string
type ExternalDecl ¶
type ExternalDecl struct {
Kind string `json:"kind"`
Pos Position `json:"pos"`
Name string `json:"name"`
// Async marks a function that runs concurrently and may fail. It is a
// keyword rather than an annotation because it changes the Go signature the
// package must provide.
Async bool `json:"async,omitempty"`
// Live marks a function that yields many values over time rather than
// settling once. It is a keyword for the same reason Async is: the Go
// signature becomes an iter.Seq2 over the result type, with a leading
// context that is mandatory rather than optional, because an endless source
// has to be stoppable.
Live bool `json:"live,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
Result TypeRef `json:"result"`
}
type ForNode ¶
type FormatParser ¶
type FormatParser interface {
ParseBody(*BodyContext, string) ([]Node, *Terminator, error)
}
FormatParser owns format tokenization and discovers embedded template boundaries. The shared BodyContext parses those boundaries and recursively calls the same format parser for control bodies.
type IdentifierExpr ¶
type IfNode ¶
type ImportDecl ¶
type LiteralExpr ¶
type MemberExpr ¶
type Module ¶
type Module struct {
Pos Position `json:"pos"`
Package *PackageDecl `json:"package,omitempty"`
Imports []ImportDecl `json:"imports,omitempty"`
Declarations []Declaration `json:"declarations"`
}
Module is the format-neutral root of a template source file.
func ParseModule ¶
func ParseModule(filename, source string, roots []RootDeclaration) (*Module, error)
ParseModule parses standard declarations plus the registered format roots.
type Node ¶
type Node interface {
NodeType() string
}
Node is a body AST node produced either by the shared parser or a registered format parser. Type IDs are namespaced as <language>:<node-type>.
type PackageDecl ¶
type ParseError ¶
ParseError reports a stable source location for syntax diagnostics.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Position ¶
Position is a one-based source position. Offset is intentionally not part of the serialized AST; parsers use offsets internally while later compiler stages report the stable line and column pair.
type RootDeclaration ¶
type RootDeclaration struct {
Keyword string
NodeType string
OutputPrefix string
Context string
Parser FormatParser
}
RootDeclaration registers one format-specific declaration with the shared root driver.
type TemplateDecl ¶
type TemplateDecl struct {
Kind string `json:"kind"`
Pos Position `json:"pos"`
Exported bool `json:"exported"`
Annotations []Annotation `json:"annotations,omitempty"`
Name string `json:"name"`
Parameters []Parameter `json:"parameters,omitempty"`
Output TypeRef `json:"output"`
Body any `json:"body"`
}
func (*TemplateDecl) Annotation ¶ added in v0.1.16
func (d *TemplateDecl) Annotation(name string) (Annotation, bool)
Annotation returns the declaration's annotation with the given name.
type Terminator ¶
type Terminator struct {
Kind TerminatorKind
Pos Position
Header string
HeaderOffset int
ContentOffset int
}
Terminator is discovered by a format parser and interpreted by the shared control parser.
type TerminatorKind ¶
type TerminatorKind string
const ( TerminatorRoot TerminatorKind = "root" TerminatorElse TerminatorKind = "else" TerminatorElseIf TerminatorKind = "else-if" TerminatorEndIf TerminatorKind = "end-if" TerminatorEndFor TerminatorKind = "end-for" TerminatorFallback TerminatorKind = "fallback" TerminatorRecover TerminatorKind = "recover" TerminatorEndAwait TerminatorKind = "end-await" )
type TypeRef ¶
type TypeRef struct {
Pos Position `json:"pos"`
Name string `json:"name"`
Arguments []TypeRef `json:"arguments,omitempty"`
Array bool `json:"array,omitempty"`
Optional bool `json:"optional,omitempty"`
// Async marks a value the caller starts and the template waits for in an
// await clause. It modifies the whole type expression, so `async Order[]`
// is one pending array rather than an array of pending values.
Async bool `json:"async,omitempty"`
}
TypeRef represents named, generic, array, optional, and asynchronous types without binding them to Go types during parsing.