syntax

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorAt

func ErrorAt(filename, source string, localOffset, baseOffset int, message string) error

ErrorAt constructs a parser diagnostic for a format-specific body parser.

func ErrorAtPosition

func ErrorAtPosition(filename, source string, localOffset, baseOffset int, basePos Position, message string) error

ErrorAtPosition constructs a diagnostic for a source fragment while keeping its file-global byte offset and line/column position.

Types

type BinaryExpr

type BinaryExpr struct {
	Kind     string   `json:"kind"`
	Pos      Position `json:"pos"`
	Operator string   `json:"operator"`
	Left     Expr     `json:"left"`
	Right    Expr     `json:"right"`
}

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) ErrorAt

func (c *BodyContext) ErrorAt(offset int, message string) error

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 CallExpr

type CallExpr struct {
	Kind      string   `json:"kind"`
	Pos       Position `json:"pos"`
	Callee    Expr     `json:"callee"`
	Arguments []Expr   `json:"arguments,omitempty"`
}

type ConditionalExpr

type ConditionalExpr struct {
	Kind      string   `json:"kind"`
	Pos       Position `json:"pos"`
	Condition Expr     `json:"condition"`
	Then      Expr     `json:"then"`
	Else      Expr     `json:"else"`
}

type Declaration

type Declaration interface {
	// contains filtered or unexported methods
}

Declaration is implemented by all root declarations.

type Embedded

type Embedded struct {
	Text          string
	StartOffset   int
	ContentOffset int
}

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 EnumMember struct {
	Pos  Position `json:"pos"`
	Name string   `json:"name"`
}

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr is the shared expression AST embedded by every output format.

func ParseExpression

func ParseExpression(filename, source string, baseOffset int) (Expr, error)

ParseExpression parses a complete shared template expression.

func ParseExpressionAt

func ParseExpressionAt(filename, source string, baseOffset int, basePos Position) (Expr, error)

ParseExpressionAt parses an expression whose first byte starts at baseOffset and basePos in its containing template file.

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"`
	Parameters []Parameter `json:"parameters,omitempty"`
	Result     TypeRef     `json:"result"`
}

type Field

type Field struct {
	Pos  Position `json:"pos"`
	Name string   `json:"name"`
	Type TypeRef  `json:"type"`
}

type ForNode

type ForNode struct {
	Kind     string   `json:"kind"`
	Pos      Position `json:"pos"`
	Context  string   `json:"context"`
	Variable string   `json:"variable"`
	Index    string   `json:"index,omitempty"`
	Iterable Expr     `json:"iterable"`
	Body     []Node   `json:"body"`
}

func (*ForNode) NodeType

func (n *ForNode) NodeType() string

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 IdentifierExpr struct {
	Kind string   `json:"kind"`
	Pos  Position `json:"pos"`
	Name string   `json:"name"`
}

type IfNode

type IfNode struct {
	Kind      string   `json:"kind"`
	Pos       Position `json:"pos"`
	Context   string   `json:"context"`
	Condition Expr     `json:"condition"`
	Then      []Node   `json:"then"`
	Else      []Node   `json:"else,omitempty"`
}

func (*IfNode) NodeType

func (n *IfNode) NodeType() string

type ImportDecl

type ImportDecl struct {
	Pos   Position `json:"pos"`
	Path  string   `json:"path"`
	Alias string   `json:"alias,omitempty"`
}

type IndexExpr

type IndexExpr struct {
	Kind   string   `json:"kind"`
	Pos    Position `json:"pos"`
	Object Expr     `json:"object"`
	Index  Expr     `json:"index"`
}

type LiteralExpr

type LiteralExpr struct {
	Kind      string   `json:"kind"`
	Pos       Position `json:"pos"`
	ValueKind string   `json:"valueKind"`
	Value     any      `json:"value"`
}

type MemberExpr

type MemberExpr struct {
	Kind   string   `json:"kind"`
	Pos    Position `json:"pos"`
	Object Expr     `json:"object"`
	Member string   `json:"member"`
}

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 PackageDecl struct {
	Kind string   `json:"kind"`
	Pos  Position `json:"pos"`
	Name string   `json:"name"`
}

type Parameter

type Parameter struct {
	Pos  Position `json:"pos"`
	Name string   `json:"name"`
	Type TypeRef  `json:"type"`
}

type ParseError

type ParseError struct {
	Filename string
	Offset   int
	Line     int
	Column   int
	Message  string
}

ParseError reports a stable source location for syntax diagnostics.

func (*ParseError) Error

func (e *ParseError) Error() string

type Position

type Position struct {
	Line int `json:"line"`
	Col  int `json:"col"`
}

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"`
	Name       string      `json:"name"`
	Parameters []Parameter `json:"parameters,omitempty"`
	Output     TypeRef     `json:"output"`
	Body       any         `json:"body"`
}

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"
)

type TypeDecl

type TypeDecl struct {
	Kind   string   `json:"kind"`
	Pos    Position `json:"pos"`
	Name   string   `json:"name"`
	Fields []Field  `json:"fields"`
}

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"`
}

TypeRef represents named, generic, array, and optional types without binding them to Go types during parsing.

type UnaryExpr

type UnaryExpr struct {
	Kind     string   `json:"kind"`
	Pos      Position `json:"pos"`
	Operator string   `json:"operator"`
	Operand  Expr     `json:"operand"`
}

Jump to

Keyboard shortcuts

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