sfc

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sfc provides a parser for GoSPA Single File Components (.gospa).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OffsetToPosition added in v0.1.32

func OffsetToPosition(input string, offset int) (int, int)

OffsetToPosition converts a byte offset to a (line, column) coordinate.

Types

type Attribute added in v0.1.32

type Attribute struct {
	Name         string
	Value        string
	IsExpression bool // If the value is a {expression}
}

Attribute represents an HTML attribute.

type BaseNode added in v0.1.32

type BaseNode struct {
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

BaseNode contains common fields for all nodes.

func (BaseNode) End added in v0.1.32

func (n BaseNode) End() (int, int)

End returns the ending line and column of the node.

func (BaseNode) Pos added in v0.1.32

func (n BaseNode) Pos() (int, int)

Pos returns the starting line and column of the node.

type Block

type Block struct {
	Type       string // "script", "template", "style"
	Lang       string // e.g., "go", "ts", "css"
	Content    string
	ByteOffset int // Start of the content block in the original source
	Line       int // 0-indexed line number
	Column     int // 0-indexed column number
}

Block represents a section of a .gospa file.

type CommentNode added in v0.1.32

type CommentNode struct {
	BaseNode
	Content string
}

CommentNode represents an HTML comment.

type ComponentNode added in v0.1.32

type ComponentNode struct {
	BaseNode
	Name       string
	Attributes []Attribute
	Children   []Node
}

ComponentNode represents a component call (@Component).

type DiagnosticError added in v0.1.39

type DiagnosticError struct {
	Line       int
	Column     int
	Message    string
	Suggestion string
	Snippet    string
}

DiagnosticError is a structured compile diagnostic with exact source location and optional remediation guidance.

func (*DiagnosticError) Error added in v0.1.39

func (e *DiagnosticError) Error() string

Error implements error.

type EachNode added in v0.1.32

type EachNode struct {
	BaseNode
	Iteratee string
	As       string
	Children []Node
}

EachNode represents a {#each} block.

type ElementNode added in v0.1.32

type ElementNode struct {
	BaseNode
	TagName     string
	Attributes  []Attribute
	Children    []Node
	SelfClosing bool
}

ElementNode represents an HTML element.

type ElseIfNode added in v0.1.32

type ElseIfNode struct {
	BaseNode
	Condition string
	Then      []Node
}

ElseIfNode represents an {:else if} block.

type ExpressionNode added in v0.1.32

type ExpressionNode struct {
	BaseNode
	Content string
}

ExpressionNode represents a {expression}.

type IfNode added in v0.1.32

type IfNode struct {
	BaseNode
	Condition string
	Then      []Node
	ElseIfs   []ElseIfNode
	Else      []Node
}

IfNode represents a {#if} block.

type Node added in v0.1.32

type Node interface {
	Pos() (int, int) // Start Line, Column
	End() (int, int) // End Line, Column
}

Node represents a node in the template AST.

type NodeType added in v0.1.32

type NodeType int

NodeType identifies the type of an AST node.

const (
	NodeElement NodeType = iota
	NodeText
	NodeComment
	NodeIf
	NodeEach
	NodeSnippet
	NodeComponent
	NodeExpression
)

NodeElement and following constants identify the type of an AST node.

type SFC

type SFC struct {
	FrontMatter map[string]string
	Script      Block
	ScriptTS    Block
	Template    Block
	Style       Block
}

SFC represents the parsed structure of a .gospa file.

func Parse

func Parse(input string) (*SFC, error)

Parse splits a .gospa file into its component blocks.

type SnippetNode added in v0.1.32

type SnippetNode struct {
	BaseNode
	Name     string
	Args     string
	Children []Node
}

SnippetNode represents a {#snippet} definition.

type TemplateParser added in v0.1.32

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

TemplateParser parses a GoSPA template string into an AST.

func NewTemplateParser added in v0.1.32

func NewTemplateParser(input string, offset int, line, col int) *TemplateParser

NewTemplateParser creates a new TemplateParser.

func (*TemplateParser) Parse added in v0.1.32

func (p *TemplateParser) Parse() ([]Node, error)

Parse returns the root list of nodes.

type TextNode added in v0.1.32

type TextNode struct {
	BaseNode
	Content string
}

TextNode represents plain text.

Jump to

Keyboard shortcuts

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