clientlang

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package clientlang parses GOWDK component-local client handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalExpr

func CanonicalExpr(source string) (string, error)

CanonicalExpr returns a deterministic representation of the supported expression subset. It is intended for compiler fingerprints, not for source rewriting.

func CanonicalStatement

func CanonicalStatement(statement string) string

CanonicalStatement returns a deterministic representation of the supported client statement subset. It is intended for fingerprints only.

func EvalBool

func EvalBool(source string, values map[string]string) (bool, error)

EvalBool evaluates a supported expression as a bool against scalar values.

func EvalScalar

func EvalScalar(source string, values map[string]string) (string, error)

EvalScalar evaluates a supported expression and returns the browser-visible scalar string representation.

func EvalValue

func EvalValue(source string, values map[string]string) (any, error)

EvalValue evaluates a supported expression and returns its typed value.

func ExprCalls

func ExprCalls(source string) ([]string, error)

ExprCalls returns helper function call names from a syntactically valid expression. It does not require type information.

func ExprFields

func ExprFields(source string) ([]string, error)

ExprFields returns identifier references from a syntactically valid expression. It does not require type information.

func IsFunctionCall

func IsFunctionCall(expr string) (string, bool)

IsFunctionCall reports whether expr is a no-argument client function call.

Types

type BinaryExpr

type BinaryExpr struct {
	Op          string
	Left, Right Expr
	Span        ExprSourceSpan
}

BinaryExpr applies a binary operator.

type Bootstrap

type Bootstrap struct {
	Handlers map[string]Handler `json:"handlers,omitempty"`
	Helpers  map[string]Helper  `json:"helpers,omitempty"`
	Emits    map[string]Emit    `json:"emits,omitempty"`
	Stores   []string           `json:"stores,omitempty"`
	Mount    []string           `json:"mount,omitempty"`
	Destroy  []string           `json:"destroy,omitempty"`
	Effects  []Effect           `json:"effects,omitempty"`
	Computed []Computed         `json:"computed,omitempty"`
}

Bootstrap is the runtime payload emitted into data-gowdk-client when a component has lifecycle/effect blocks.

type Call

type Call struct {
	Name string
	Args []string
}

Call is a component-local function invocation expression.

func ParseCall

func ParseCall(expr string) (Call, bool)

ParseCall reports whether expr is a component-local function call.

type CallExpr

type CallExpr struct {
	Name string
	Args []Expr
	Span ExprSourceSpan
}

CallExpr invokes a component-local helper function.

type Computed

type Computed struct {
	Name     string `json:"name"`
	Type     string `json:"-"`
	Expr     string `json:"expr"`
	Span     Span   `json:"-"`
	ExprSpan Span   `json:"-"`
}

Computed describes one derived component-local value.

func OrderComputed

func OrderComputed(computeds []Computed) ([]Computed, error)

OrderComputed returns computed values in dependency order and rejects cycles.

type ConditionalExpr

type ConditionalExpr struct {
	Cond Expr
	Then Expr
	Else Expr
	Span ExprSourceSpan
}

ConditionalExpr chooses between two expressions from a bool condition.

type Effect

type Effect struct {
	Field          string   `json:"field"`
	Statements     []string `json:"statements"`
	Cleanup        []string `json:"cleanup,omitempty"`
	StatementSpans []Span   `json:"-"`
	CleanupSpans   []Span   `json:"-"`
	Span           Span     `json:"-"`
}

Effect is a dependency-triggered client block.

type Emit

type Emit struct {
	Name       string      `json:"-"`
	Params     []string    `json:"params,omitempty"`
	ParamTypes []ValueType `json:"-"`
}

Emit describes one component event exposed to parent component calls.

type EmitCall

type EmitCall struct {
	Name string
	Args []string
}

EmitCall is a component event dispatch statement.

func ParseEmitCall

func ParseEmitCall(expr string) (EmitCall, bool)

ParseEmitCall reports whether expr is an emit event(args...) statement.

type Expr

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

Expr describes a parsed client expression.

func ParseExpr

func ParseExpr(source string) (Expr, error)

ParseExpr parses the supported client expression subset.

func ParseExprWithSpans

func ParseExprWithSpans(source string) (Expr, error)

ParseExprWithSpans parses the supported client expression subset and records 1-based source columns on every expression node.

type ExprFunction

type ExprFunction struct {
	Params []ValueType
	Return ValueType
}

ExprFunction describes a return-valued helper callable from expressions.

type ExprSourceSpan

type ExprSourceSpan struct {
	StartColumn int
	EndColumn   int
}

ExprSourceSpan is a 1-based column span within the expression source. End is exclusive.

func ExprSpan

func ExprSpan(expr Expr) ExprSourceSpan

ExprSpan returns the source span recorded for expr.

type ExprValidationError

type ExprValidationError struct {
	Span ExprSourceSpan
	Err  error
}

ExprValidationError wraps an expression validation failure with the source columns of the expression node that failed.

func (ExprValidationError) Error

func (err ExprValidationError) Error() string

func (ExprValidationError) Unwrap

func (err ExprValidationError) Unwrap() error

type Function

type Function struct {
	Name           string
	Async          bool
	Params         []Param
	ReturnType     string
	Statements     []string
	StatementSpans []Span
	Span           Span
}

Function is a component-local browser handler.

type Handler

type Handler struct {
	Params     []string    `json:"params,omitempty"`
	ParamTypes []ValueType `json:"-"`
	Async      bool        `json:"async,omitempty"`
	Statements []string    `json:"statements"`
}

Handler is the runtime representation emitted into island bootstrap data.

type Helper

type Helper struct {
	Params     []string    `json:"params,omitempty"`
	ParamTypes []ValueType `json:"-"`
	ReturnType ValueType   `json:"-"`
	Return     string      `json:"return"`
}

Helper is a return-valued component-local function callable from expressions. Helpers cannot be called directly as event handlers.

type IdentExpr

type IdentExpr struct {
	Name string
	Span ExprSourceSpan
}

IdentExpr reads a state, prop, param, or local name.

type IndexExpr

type IndexExpr struct {
	X     Expr
	Index Expr
	Span  ExprSourceSpan
}

IndexExpr reads an item from an array expression.

type LiteralExpr

type LiteralExpr struct {
	Type  ValueType
	Value string
	Span  ExprSourceSpan
}

LiteralExpr is a scalar literal.

type MemberExpr

type MemberExpr struct {
	X    Expr
	Name string
	Span ExprSourceSpan
}

MemberExpr reads a field from an object expression.

type Param

type Param struct {
	Name string
	Type string
}

Param describes one typed function parameter.

type ParseError

type ParseError struct {
	Line int
	Err  error
}

ParseError reports a client {} parse failure with a 1-based line relative to the client block body when available.

func (*ParseError) Error

func (err *ParseError) Error() string

func (*ParseError) Unwrap

func (err *ParseError) Unwrap() error

type Program

type Program struct {
	Functions    []Function
	Mount        []string
	MountSpans   []Span
	Destroy      []string
	DestroySpans []Span
	Effects      []Effect
	Refs         []Ref
	Uses         []Use
	Computed     []Computed
}

Program is the parsed representation of a component client {} block.

func Parse

func Parse(source string) (Program, error)

Parse parses the first component client {} language slice.

func (Program) Canonical

func (program Program) Canonical() string

Canonical returns a deterministic representation used for component redundancy checks.

func (Program) HandlerMap

func (program Program) HandlerMap() map[string]Handler

HandlerMap returns deterministic handlers keyed by function name.

func (Program) HasLifecycle

func (program Program) HasLifecycle() bool

HasLifecycle reports whether the program needs the runtime bootstrap envelope.

func (Program) HelperMap

func (program Program) HelperMap() map[string]Helper

HelperMap returns deterministic return-valued helpers keyed by function name.

func (Program) NeedsBootstrap

func (program Program) NeedsBootstrap() bool

NeedsBootstrap reports whether the program needs the runtime bootstrap envelope instead of the older direct handler map.

func (Program) OrderedComputed

func (program Program) OrderedComputed() ([]Computed, error)

OrderedComputed returns computed values in dependency order. References to other computed names must be evaluated before the dependent value.

func (Program) RefMap

func (program Program) RefMap() map[string]Ref

RefMap returns declared DOM refs keyed by name.

func (Program) StoreNames

func (program Program) StoreNames() []string

StoreNames returns deterministic page-scoped store names used by the program.

func (Program) UseMap

func (program Program) UseMap() map[string]Use

UseMap returns declared page-scoped store uses keyed by store name.

type Ref

type Ref struct {
	Name string
	Kind string
}

Ref is a declared DOM reference.

type Span

type Span struct {
	StartLine int
	EndLine   int
}

Span is a 1-based source span relative to the component client {} body.

type UnaryExpr

type UnaryExpr struct {
	Op   string
	X    Expr
	Span ExprSourceSpan
}

UnaryExpr applies a unary operator.

type Use

type Use struct {
	Name         string
	PackageAlias string
	StoreName    string
	Span         Span
}

Use declares one page-scoped store used by this component.

type ValueType

type ValueType string

ValueType is the small client expression type universe.

const (
	TypeUnknown ValueType = ""
	TypeString  ValueType = "string"
	TypeInt     ValueType = "int"
	TypeFloat   ValueType = "float"
	TypeBool    ValueType = "bool"
	TypeNil     ValueType = "nil"
	TypeObject  ValueType = "object"
	TypeArray   ValueType = "array"
)

func CheckExpr

func CheckExpr(source string, symbols map[string]ValueType) (ValueType, []string, error)

CheckExpr parses and type-checks a client expression against symbols.

func CheckExprWithFunctions

func CheckExprWithFunctions(source string, symbols map[string]ValueType, functions map[string]ExprFunction) (ValueType, []string, error)

CheckExprWithFunctions parses and type-checks a client expression against value symbols and return-valued helper functions.

func NormalizeType

func NormalizeType(value string) ValueType

NormalizeType maps Go/GOWDK scalar type names into client expression types.

Jump to

Keyboard shortcuts

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