node

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultMaxColumns = 80

DefaultMaxColumns is the line-width budget used by the NEW_LINE_CALC formatting mode when no explicit MaxColumns is set.

Variables

This section is empty.

Functions

func Code

func Code(n Coder, opt ...CodeOption) string

func CodeW

func CodeW(w io.Writer, n Coder, opt ...CodeOption)

func FormatFuncReturn added in v0.0.2

func FormatFuncReturn(ret []*TypedIdentExpr) string

FormatFuncReturn renders an optional function return-type list as " <T1, T2, ...>". It returns an empty string when there are no return types.

func IsExpr

func IsExpr(n Node) (ok bool)

func IsStatement

func IsStatement(v Node) (ok bool)

IsStatement returns true if given value is implements interface{ StmtNode() }.

func Lit

func Lit(value string, pos source.Pos) ast.Literal

func WithCallArgs added in v0.0.2

func WithCallArgs[T interface{ GetCallArgs() *CallArgs }](e T, do func(args *CallArgs)) T

func WriteFuncReturn added in v0.0.2

func WriteFuncReturn(ctx *CodeWriteContext, ret []*TypedIdentExpr)

WriteFuncReturn is the WriteCode counterpart of FormatFuncReturn: it renders the return-type list applying the union spacing rule (` | ` around each `|`), inline within the `< >`.

Types

type ArgVarLit

type ArgVarLit struct {
	TokenPos source.Pos
	Value    Expr
}

ArgVarLit represents an variadic of argument.

func ArgVar

func ArgVar(pos source.Pos, value Expr) *ArgVarLit

func (*ArgVarLit) End

func (e *ArgVarLit) End() source.Pos

func (*ArgVarLit) ExprNode

func (e *ArgVarLit) ExprNode()

func (*ArgVarLit) Pos

func (e *ArgVarLit) Pos() source.Pos

func (*ArgVarLit) String

func (e *ArgVarLit) String() string

func (*ArgVarLit) WriteCode

func (e *ArgVarLit) WriteCode(ctx *CodeWriteContext)

type ArgsKeywordExpr

type ArgsKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func ArgsKW

func ArgsKW(pos source.Pos) *ArgsKeywordExpr

func (*ArgsKeywordExpr) End

func (c *ArgsKeywordExpr) End() source.Pos

func (*ArgsKeywordExpr) ExprNode

func (c *ArgsKeywordExpr) ExprNode()

func (*ArgsKeywordExpr) Pos

func (c *ArgsKeywordExpr) Pos() source.Pos

func (*ArgsKeywordExpr) String

func (c *ArgsKeywordExpr) String() string

func (*ArgsKeywordExpr) WriteCode

func (c *ArgsKeywordExpr) WriteCode(ctx *CodeWriteContext)

type ArgsList

type ArgsList struct {
	Var    *TypedIdentExpr
	Values []*TypedIdentExpr
}

ArgsList represents a list of identifiers.

func Args

func Args(vari *IdentExpr, names ...Expr) ArgsList

func (*ArgsList) End

func (n *ArgsList) End() source.Pos

End returns the position of first character immediately after the node.

func (*ArgsList) NumFields

func (n *ArgsList) NumFields() int

NumFields returns the number of fields.

func (*ArgsList) Pos

func (n *ArgsList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ArgsList) PrependValue

func (n *ArgsList) PrependValue(v ...*TypedIdentExpr)

func (*ArgsList) String

func (n *ArgsList) String() string

type ArrayComprehension added in v0.0.2

type ArrayComprehension struct {
	LBrack  source.Pos
	Element Expr
	Clauses []*ComprehensionClause
	RBrack  source.Pos
}

ArrayComprehension represents `[elem for x in it if cond ...]`.

func (*ArrayComprehension) End added in v0.0.2

func (e *ArrayComprehension) End() source.Pos

End returns the position of first character immediately after the node.

func (*ArrayComprehension) ExprNode added in v0.0.2

func (e *ArrayComprehension) ExprNode()

func (*ArrayComprehension) Pos added in v0.0.2

func (e *ArrayComprehension) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ArrayComprehension) String added in v0.0.2

func (e *ArrayComprehension) String() string

func (*ArrayComprehension) WriteCode added in v0.0.2

func (e *ArrayComprehension) WriteCode(ctx *CodeWriteContext)

type ArrayExpr

type ArrayExpr struct {
	Elements []Expr
	LBrack   source.Pos
	RBrack   source.Pos
}

ArrayExpr represents an array literal.

func Array

func Array(lbracket, rbracket source.Pos, list ...Expr) *ArrayExpr

func (*ArrayExpr) End

func (e *ArrayExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ArrayExpr) ExprNode

func (e *ArrayExpr) ExprNode()

func (*ArrayExpr) Pos

func (e *ArrayExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ArrayExpr) String

func (e *ArrayExpr) String() string

func (*ArrayExpr) WriteCode

func (e *ArrayExpr) WriteCode(ctx *CodeWriteContext)

type AssignStmt

type AssignStmt struct {
	LHS      []Expr
	RHS      []Expr
	Token    token.Token
	TokenPos source.Pos
}

AssignStmt represents an assignment statement.

func SAssign

func SAssign(
	lhs, rhs []Expr,
	token token.Token,
	pos source.Pos,
) *AssignStmt

func (*AssignStmt) End

func (s *AssignStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*AssignStmt) StmtNode

func (s *AssignStmt) StmtNode()

func (*AssignStmt) String

func (s *AssignStmt) String() string

func (*AssignStmt) WriteCode

func (s *AssignStmt) WriteCode(ctx *CodeWriteContext)

type BadDecl

type BadDecl struct {
	From, To source.Pos // position range of bad declaration
}

A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.

func (*BadDecl) End

func (d *BadDecl) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadDecl) Pos

func (d *BadDecl) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadDecl) String

func (*BadDecl) String() string

func (*BadDecl) WriteCode

func (d *BadDecl) WriteCode(ctx *CodeWriteContext)

type BadExpr

type BadExpr struct {
	From source.Pos
	To   source.Pos
}

BadExpr represents a bad expression.

func (*BadExpr) End

func (e *BadExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadExpr) ExprNode

func (e *BadExpr) ExprNode()

func (*BadExpr) Pos

func (e *BadExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadExpr) String

func (e *BadExpr) String() string

func (*BadExpr) WriteCode

func (e *BadExpr) WriteCode(ctx *CodeWriteContext)

type BadStmt

type BadStmt struct {
	From source.Pos
	To   source.Pos
}

BadStmt represents a bad statement.

func (*BadStmt) End

func (s *BadStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadStmt) Pos

func (s *BadStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadStmt) StmtNode

func (s *BadStmt) StmtNode()

func (*BadStmt) String

func (s *BadStmt) String() string

func (*BadStmt) WriteCode

func (s *BadStmt) WriteCode(ctx *CodeWriteContext)

type BinaryExpr

type BinaryExpr struct {
	LHS      Expr
	RHS      Expr
	Token    token.Token
	TokenPos source.Pos
}

BinaryExpr represents a binary operator expression.

func EBinary

func EBinary(
	x, y Expr,
	op token.Token,
	pos source.Pos,
) *BinaryExpr

func (*BinaryExpr) End

func (e *BinaryExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*BinaryExpr) ExprNode

func (e *BinaryExpr) ExprNode()

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

func (*BinaryExpr) WriteCode

func (e *BinaryExpr) WriteCode(ctx *CodeWriteContext)

func (*BinaryExpr) WriteCodeWithParen added in v0.0.2

func (e *BinaryExpr) WriteCodeWithParen(ctx *CodeWriteContext, paren bool)

type BlockExpr

type BlockExpr struct {
	*BlockStmt
}

func EBlock

func EBlock(lbrace, rbrace source.Pos, list ...Stmt) *BlockExpr

func (BlockExpr) ExprNode

func (b BlockExpr) ExprNode()

type BlockStmt

type BlockStmt struct {
	Stmts  Stmts
	LBrace ast.Literal
	RBrace ast.Literal
	Scoped bool
	// DeferClaimed marks a function body whose `defer` statements have already
	// been claimed by an enclosing defer wrapper, so it must not be wrapped
	// again (its defers register to the outer $__defers list).
	DeferClaimed bool
}

BlockStmt represents a block statement.

func SBlock

func SBlock(lbrace, rbrace source.Pos, list ...Stmt) *BlockStmt

func SBlockLit

func SBlockLit(lbrace, rbrace ast.Literal, list ...Stmt) *BlockStmt

func (*BlockStmt) End

func (s *BlockStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BlockStmt) IsEmtpy added in v0.0.2

func (s *BlockStmt) IsEmtpy() bool

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BlockStmt) StmtNode

func (s *BlockStmt) StmtNode()

func (*BlockStmt) String

func (s *BlockStmt) String() string

func (*BlockStmt) WriteCode

func (s *BlockStmt) WriteCode(ctx *CodeWriteContext)

type BoolExpr

type BoolExpr interface {
	Expr
	Bool() bool
}

type BoolLit

type BoolLit struct {
	Value    bool
	ValuePos source.Pos
	Literal  string
}

BoolLit represents a boolean literal.

func Bool

func Bool(value bool, pos source.Pos) *BoolLit

func (*BoolLit) Bool

func (e *BoolLit) Bool() bool

func (*BoolLit) End

func (e *BoolLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*BoolLit) ExprNode

func (e *BoolLit) ExprNode()

func (*BoolLit) Pos

func (e *BoolLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BoolLit) String

func (e *BoolLit) String() string

func (*BoolLit) WriteCode

func (e *BoolLit) WriteCode(ctx *CodeWriteContext)

type BranchStmt

type BranchStmt struct {
	Token    token.Token
	TokenPos source.Pos
	Label    *IdentExpr
}

BranchStmt represents a branch statement.

func SBreak

func SBreak(pos source.Pos) *BranchStmt

func SContinue

func SContinue(pos source.Pos) *BranchStmt

func (*BranchStmt) End

func (s *BranchStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BranchStmt) Pos

func (s *BranchStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BranchStmt) StmtNode

func (s *BranchStmt) StmtNode()

func (*BranchStmt) String

func (s *BranchStmt) String() string

func (*BranchStmt) WriteCode

func (s *BranchStmt) WriteCode(ctx *CodeWriteContext)

type BytesLit added in v0.0.2

type BytesLit struct {
	// Prefix is the literal prefix (BytesLitHex or BytesLitRaw).
	Prefix BytesLitPrefix
	// PrefixPos is the position of the prefix letter.
	PrefixPos source.Pos
	// Str is the underlying string literal node (*StrLit, *RawStrLit,
	// *HeredocLit or *RawHeredocLit).
	Str Expr
}

BytesLit represents a prefixed string literal that evaluates to a byte slice.

The prefix is a single letter immediately preceding the opening string delimiter (no whitespace): h for a hexadecimal sequence (h"ffccf1c2") and b for the raw UTF-8 bytes of the content (b"Hello"). Any string form may be used as the body: a regular string, a raw string, a heredoc or a raw heredoc.

func (*BytesLit) Bytes added in v0.0.2

func (e *BytesLit) Bytes() ([]byte, error)

Bytes decodes the literal into its byte slice value. For BytesLitHex the content is parsed as hexadecimal (whitespace ignored); for BytesLitRaw the UTF-8 bytes of the content are returned unchanged.

func (*BytesLit) End added in v0.0.2

func (e *BytesLit) End() source.Pos

End returns the position immediately after the underlying string literal.

func (*BytesLit) ExprNode added in v0.0.2

func (e *BytesLit) ExprNode()

func (*BytesLit) Pos added in v0.0.2

func (e *BytesLit) Pos() source.Pos

Pos returns the position of the prefix letter.

func (*BytesLit) StrValue added in v0.0.2

func (e *BytesLit) StrValue() string

StrValue returns the decoded string content of the underlying string literal.

func (*BytesLit) String added in v0.0.2

func (e *BytesLit) String() string

func (*BytesLit) WriteCode added in v0.0.2

func (e *BytesLit) WriteCode(ctx *CodeWriteContext)

type BytesLitPrefix added in v0.0.2

type BytesLitPrefix string

BytesLitPrefix identifies how a BytesLit's underlying string is decoded into a byte slice.

const (
	// BytesLitHex decodes the string content as a hexadecimal byte sequence,
	// e.g. h"ffccf1c2". Whitespace inside the string is ignored.
	BytesLitHex BytesLitPrefix = "h"
	// BytesLitRaw uses the UTF-8 bytes of the string content as-is,
	// e.g. b"Hello".
	BytesLitRaw BytesLitPrefix = "b"
)

type CallArgs

type CallArgs struct {
	LParen    source.Pos
	RParen    source.Pos
	Args      CallExprPositionalArgs
	NamedArgs CallExprNamedArgs
}

func NewCallArgs added in v0.0.2

func NewCallArgs(LParen source.Pos, RParen source.Pos) *CallArgs

func (*CallArgs) Arg added in v0.0.2

func (c *CallArgs) Arg(e ...Expr) *CallArgs

func (*CallArgs) ArgVar added in v0.0.2

func (c *CallArgs) ArgVar(pos source.Pos, e Expr) *CallArgs

func (*CallArgs) End

func (c *CallArgs) End() source.Pos

End returns the position of first character immediately after the node.

func (*CallArgs) NamedFlag added in v0.0.2

func (c *CallArgs) NamedFlag(e ...Expr) *CallArgs

func (*CallArgs) NamedValue added in v0.0.2

func (c *CallArgs) NamedValue(e ...Expr) *CallArgs

func (*CallArgs) Pos

func (c *CallArgs) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CallArgs) String

func (c *CallArgs) String() string

func (*CallArgs) StringArg

func (c *CallArgs) StringArg(w io.Writer, lbrace, rbrace string)

func (*CallArgs) StringW

func (c *CallArgs) StringW(w io.Writer)

func (*CallArgs) ToFuncParams

func (c *CallArgs) ToFuncParams() (fp *FuncParams, err error)

func (*CallArgs) WriteCode

func (c *CallArgs) WriteCode(ctx *CodeWriteContext)

func (*CallArgs) WriteCodeBrace

func (c *CallArgs) WriteCodeBrace(ctx *CodeWriteContext, lbrace, rbrace string)

type CallExpr

type CallExpr struct {
	Func Expr
	CallArgs
}

CallExpr represents a function call expression.

func ECall

func ECall(
	f Expr,
	lparen, rparen source.Pos,
	args ...any,
) (ce *CallExpr)

func ECallProxy

func ECallProxy(efunc Expr) *CallExpr

func (*CallExpr) CallPos

func (e *CallExpr) CallPos() source.Pos

CallPos returns the position of the fist valid call pos

func (*CallExpr) End

func (e *CallExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*CallExpr) ExprNode

func (e *CallExpr) ExprNode()

func (*CallExpr) GetCallArgs added in v0.0.2

func (e *CallExpr) GetCallArgs() *CallArgs

func (*CallExpr) Pos

func (e *CallExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CallExpr) String

func (e *CallExpr) String() string

func (*CallExpr) WriteCode

func (e *CallExpr) WriteCode(ctx *CodeWriteContext)

type CallExprNamedArgs

type CallExprNamedArgs struct {
	Names  []*NamedArgExpr
	Values []Expr
}

CallExprNamedArgs represents a call expression keyword arguments.

func NewCallExprNamedArgs

func NewCallExprNamedArgs(
	names []*NamedArgExpr, values []Expr,
) (ce *CallExprNamedArgs)

func (*CallExprNamedArgs) Append

func (a *CallExprNamedArgs) Append(name *NamedArgExpr, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) AppendE added in v0.0.2

func (a *CallExprNamedArgs) AppendE(name Expr, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) AppendFlagE added in v0.0.2

func (a *CallExprNamedArgs) AppendFlagE(name Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) AppendFlags added in v0.0.2

func (a *CallExprNamedArgs) AppendFlags(name ...string) *CallExprNamedArgs

func (*CallExprNamedArgs) AppendS

func (a *CallExprNamedArgs) AppendS(name string, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) Get

func (a *CallExprNamedArgs) Get(name NamedArgExpr) (index int, value Expr)

func (*CallExprNamedArgs) NamesExpr

func (a *CallExprNamedArgs) NamesExpr() (r []Expr)

func (*CallExprNamedArgs) Prepend

func (a *CallExprNamedArgs) Prepend(name *NamedArgExpr, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) String

func (a *CallExprNamedArgs) String() string

func (*CallExprNamedArgs) Valid

func (a *CallExprNamedArgs) Valid() bool

func (*CallExprNamedArgs) Var

func (a *CallExprNamedArgs) Var() *NamedArgExpr

func (*CallExprNamedArgs) WriteCode

func (a *CallExprNamedArgs) WriteCode(ctx *CodeWriteContext, inNewLime, hasPositional bool)

func (*CallExprNamedArgs) WriteCodeWithFlag added in v0.0.2

func (a *CallExprNamedArgs) WriteCodeWithFlag(inNewLine, hasPositional bool, ctx *CodeWriteContext)

type CallExprPositionalArgs added in v0.0.2

type CallExprPositionalArgs struct {
	Values []Expr
	Var    *ArgVarLit
}

CallExprPositionalArgs represents a call expression arguments.

func NewCallExprArgs

func NewCallExprArgs(
	argVar *ArgVarLit,
	args ...Expr,
) (ce CallExprPositionalArgs)

func (*CallExprPositionalArgs) AppendValues added in v0.0.2

func (a *CallExprPositionalArgs) AppendValues(e ...Expr)

func (*CallExprPositionalArgs) String added in v0.0.2

func (a *CallExprPositionalArgs) String() string

func (*CallExprPositionalArgs) Valid added in v0.0.2

func (a *CallExprPositionalArgs) Valid() bool

func (*CallExprPositionalArgs) WriteCodeWithNamed added in v0.0.2

func (a *CallExprPositionalArgs) WriteCodeWithNamed(ctx *CodeWriteContext, inNewLine, hasNamed bool)

type CalleeKeywordExpr

type CalleeKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func CaleeKW

func CaleeKW(pos source.Pos) *CalleeKeywordExpr

func (*CalleeKeywordExpr) End

func (c *CalleeKeywordExpr) End() source.Pos

func (*CalleeKeywordExpr) ExprNode

func (c *CalleeKeywordExpr) ExprNode()

func (*CalleeKeywordExpr) Pos

func (c *CalleeKeywordExpr) Pos() source.Pos

func (*CalleeKeywordExpr) String

func (c *CalleeKeywordExpr) String() string

func (*CalleeKeywordExpr) WriteCode

func (c *CalleeKeywordExpr) WriteCode(ctx *CodeWriteContext)

type CatchStmt

type CatchStmt struct {
	CatchPos source.Pos
	Ident    *IdentExpr // can be nil if ident is missing
	Body     *BlockStmt
}

CatchStmt represents an catch statement.

func SCatch

func SCatch(
	catchPos source.Pos,
	ident *IdentExpr,
	body *BlockStmt,
) *CatchStmt

func (*CatchStmt) End

func (s *CatchStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*CatchStmt) Pos

func (s *CatchStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CatchStmt) StmtNode

func (s *CatchStmt) StmtNode()

func (*CatchStmt) String

func (s *CatchStmt) String() string

func (*CatchStmt) WriteCode

func (s *CatchStmt) WriteCode(ctx *CodeWriteContext)

type CharLit

type CharLit struct {
	Value    rune
	ValuePos source.Pos
	Literal  string
}

CharLit represents a character literal.

func Char

func Char(value rune, pos source.Pos) *CharLit

func (*CharLit) End

func (e *CharLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*CharLit) ExprNode

func (e *CharLit) ExprNode()

func (*CharLit) Pos

func (e *CharLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CharLit) String

func (e *CharLit) String() string

func (*CharLit) WriteCode

func (e *CharLit) WriteCode(ctx *CodeWriteContext)

type ClassExpr added in v0.0.2

type ClassExpr struct {
	ClassToken TokenLit
	NameExpr   Expr
	Parents    []*ClassParentExpr
	ExtendsDoc *ast.CommentGroup
	Fields     []*ClassFieldExpr
	Props      []*ClassMemberExpr
	PropsDoc   *ast.CommentGroup
	New        []*FuncMethod
	NewDoc     *ast.CommentGroup
	Methods    []*ClassMemberExpr
	MethodsDoc *ast.CommentGroup
	LBrace     source.Pos
	RBrace     source.Pos
	Doc        *ast.CommentGroup // doc comment preceding the class; or nil
}

ClassExpr is a class literal:

class [Name] { *P, …, fields, props {…}, new …, methods {…} }

Parent classes are `*Parent` spread body items (optionally aliased as `*Parent: Alias`), alongside fields and the `props`/`new`/`methods` groups. It lowers (in the compiler) to a

Class(name; define=(Type, define) => define(; extends=…, fields=…,
    properties=…, methods=…, new=…))

call. The `define` callback binds `Type` to the in-construction class so each method, property accessor and constructor can take a typed `this Type` first parameter (injected by the compiler). NameExpr is nil for an anonymous, expression-form class.

func (*ClassExpr) End added in v0.0.2

func (e *ClassExpr) End() source.Pos

func (*ClassExpr) ExprNode added in v0.0.2

func (e *ClassExpr) ExprNode()

func (*ClassExpr) Pos added in v0.0.2

func (e *ClassExpr) Pos() source.Pos

func (*ClassExpr) String added in v0.0.2

func (e *ClassExpr) String() string

func (*ClassExpr) WriteCode added in v0.0.2

func (e *ClassExpr) WriteCode(ctx *CodeWriteContext)

type ClassFieldExpr added in v0.0.2

type ClassFieldExpr struct {
	Name   *TypedIdentExpr
	Assign source.Pos
	Value  Expr              // default value; nil when none
	Doc    *ast.CommentGroup // doc comment preceding the field; or nil
}

ClassFieldExpr is a declared field in a class body: `name`, `name = value`, `name Type = value`, or a computed default `name = (= expr)` (Value is then a *ComputedExpr, evaluated per instance).

func (*ClassFieldExpr) End added in v0.0.2

func (e *ClassFieldExpr) End() source.Pos

func (*ClassFieldExpr) ExprNode added in v0.0.2

func (e *ClassFieldExpr) ExprNode()

func (*ClassFieldExpr) Pos added in v0.0.2

func (e *ClassFieldExpr) Pos() source.Pos

func (*ClassFieldExpr) String added in v0.0.2

func (e *ClassFieldExpr) String() string

func (*ClassFieldExpr) WriteCode added in v0.0.2

func (e *ClassFieldExpr) WriteCode(ctx *CodeWriteContext)

type ClassMemberExpr added in v0.0.2

type ClassMemberExpr struct {
	NameExpr Expr
	Methods  []*FuncMethod
	Block    bool // written in the brace-block form `name { (…) … }`
	LBrace   source.Pos
	RBrace   source.Pos
	Doc      *ast.CommentGroup // doc comment preceding the member; or nil
}

ClassMemberExpr is a named method (or, inside `props {}`, a property) in a class body: a name plus one (single form) or several (brace-block form) FuncMethod overloads, sharing the func-with-methods/prop body syntax.

func (*ClassMemberExpr) End added in v0.0.2

func (e *ClassMemberExpr) End() source.Pos

func (*ClassMemberExpr) ExprNode added in v0.0.2

func (e *ClassMemberExpr) ExprNode()

func (*ClassMemberExpr) Pos added in v0.0.2

func (e *ClassMemberExpr) Pos() source.Pos

func (*ClassMemberExpr) String added in v0.0.2

func (e *ClassMemberExpr) String() string

func (*ClassMemberExpr) WriteCode added in v0.0.2

func (e *ClassMemberExpr) WriteCode(ctx *CodeWriteContext)

type ClassParentExpr added in v0.0.2

type ClassParentExpr struct {
	Type  Expr
	Alias *IdentExpr // optional; nil when written without `: alias`
}

ClassParentExpr is one parent class, written as a `*Parent` spread body item: a parent type expression (an IdentExpr or SelectorExpr) with an optional alias written after a colon (`*Base: B`).

func (*ClassParentExpr) End added in v0.0.2

func (e *ClassParentExpr) End() source.Pos

func (*ClassParentExpr) Pos added in v0.0.2

func (e *ClassParentExpr) Pos() source.Pos

func (*ClassParentExpr) String added in v0.0.2

func (e *ClassParentExpr) String() string

func (*ClassParentExpr) WriteCode added in v0.0.2

func (e *ClassParentExpr) WriteCode(ctx *CodeWriteContext)

type ClassStmt added in v0.0.2

type ClassStmt struct {
	ClassExpr
}

ClassStmt is the statement form `class Name { … }`. It compiles to `const Name = <class expression>`.

func (*ClassStmt) StmtNode added in v0.0.2

func (*ClassStmt) StmtNode()

type ClosureExpr

type ClosureExpr struct {
	ast.NodeData
	Params FuncParams
	Return []*TypedIdentExpr
	Lambda Token
	Body   Expr
}

ClosureExpr represents a function closure literal.

func EClosure

func EClosure(params *FuncParams, lambdaPos source.Pos, lambdaToken token.Token, body Expr) *ClosureExpr

func (*ClosureExpr) End

func (e *ClosureExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ClosureExpr) ExprNode

func (e *ClosureExpr) ExprNode()

func (*ClosureExpr) Pos

func (e *ClosureExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ClosureExpr) String

func (e *ClosureExpr) String() string

func (*ClosureExpr) WriteCode

func (e *ClosureExpr) WriteCode(ctx *CodeWriteContext)

type CodeBeginStmt

type CodeBeginStmt struct {
	Lit         ast.Literal
	RemoveSpace bool
	// RemoveAllSpace reports the double-dash trim suffix (`{%--`), which strips
	// ALL trailing whitespace (newlines included) from the preceding text.
	RemoveAllSpace bool
}

CodeBeginStmt is the opening delimiter of a mixed/template code block, e.g. `{%` (or `{%-`). Lit holds the literal delimiter; RemoveSpace reports the `-` trim suffix (`{%-`), which strips trailing whitespace from the preceding text at run time. The statements that follow, up to the matching CodeEndStmt, are ordinary Gad code.

func SCodeBegin

func SCodeBegin(lit ast.Literal, removeSpace bool) *CodeBeginStmt

func (CodeBeginStmt) End

func (s CodeBeginStmt) End() source.Pos

func (CodeBeginStmt) Pos

func (s CodeBeginStmt) Pos() source.Pos

func (CodeBeginStmt) SkipCode added in v0.0.2

func (CodeBeginStmt) SkipCode(ctx *CodeWriteContext) bool

func (CodeBeginStmt) StmtNode

func (s CodeBeginStmt) StmtNode()

func (CodeBeginStmt) String

func (s CodeBeginStmt) String() string

func (*CodeBeginStmt) WriteCode

func (s *CodeBeginStmt) WriteCode(ctx *CodeWriteContext)

type CodeEndStmt

type CodeEndStmt struct {
	Lit         ast.Literal
	RemoveSpace bool
	// RemoveAllSpace reports the double-dash trim prefix (`--%}`), which strips
	// ALL leading whitespace (newlines included) from the following text.
	RemoveAllSpace bool
}

CodeEndStmt is the closing delimiter of a mixed/template code block, e.g. `%}` (or `-%}`). Lit holds the literal delimiter; RemoveSpace reports the `-` trim prefix (`-%}`), which strips leading whitespace from the following text at run time.

func SCodeEnd

func SCodeEnd(lit ast.Literal, removeSpace bool) *CodeEndStmt

func (CodeEndStmt) End

func (s CodeEndStmt) End() source.Pos

func (CodeEndStmt) Pos

func (s CodeEndStmt) Pos() source.Pos

func (CodeEndStmt) SkipCode added in v0.0.2

func (CodeEndStmt) SkipCode(ctx *CodeWriteContext) bool

func (CodeEndStmt) StmtNode

func (s CodeEndStmt) StmtNode()

func (CodeEndStmt) String

func (s CodeEndStmt) String() string

func (*CodeEndStmt) WriteCode

func (s *CodeEndStmt) WriteCode(ctx *CodeWriteContext)

type CodeOption

type CodeOption func(ctx *CodeWriteContext)

func CodeFormat added in v0.0.2

func CodeFormat() CodeOption

func CodeNewLineCalc added in v0.0.2

func CodeNewLineCalc(maxColumns int) CodeOption

CodeNewLineCalc enables the column-aware (NEW_LINE_CALC) formatting mode with the given column budget (<= 0 uses DefaultMaxColumns). List constructs stay inline unless they would overflow the budget.

func CodeTranspile

func CodeTranspile(v *TranspileOptions) CodeOption

func CodeWithComments added in v0.0.2

func CodeWithComments(f *source.File, groups []*ast.CommentGroup) CodeOption

CodeWithComments threads the source comments (collected by parsing with ParseComments) into the formatter so they are preserved in the output. The file is required for line lookups (to tell trailing same-line comments from own-line ones).

func CodeWithFlags added in v0.0.2

func CodeWithFlags(flag CodeWriteContextFlag) CodeOption

func CodeWithPrefix

func CodeWithPrefix(prefix string) CodeOption

type CodeStrLit added in v0.0.2

type CodeStrLit struct {
	Literal    string
	LiteralPos source.Pos
}

CodeStrLit represents a `code … end` code-string literal: a heredoc-like form whose body is captured verbatim (it is NOT parsed or template-interpolated) and compiled to a plain Str. The `code`/`end` fences signal to editors that the body is Gad source. Two forms are accepted, a block form

code
    <body>
end

and the single-line form `code <body> end`. For the block form Value strips the least-indented body line's common indentation from every line (like a squiggly heredoc) so the embedded source dedents to its own baseline.

func (*CodeStrLit) End added in v0.0.2

func (e *CodeStrLit) End() source.Pos

End returns the position immediately after the closing `end`.

func (*CodeStrLit) ExprNode added in v0.0.2

func (e *CodeStrLit) ExprNode()

func (*CodeStrLit) Pos added in v0.0.2

func (e *CodeStrLit) Pos() source.Pos

Pos returns the position of the opening `code` keyword.

func (*CodeStrLit) String added in v0.0.2

func (e *CodeStrLit) String() string

func (*CodeStrLit) Value added in v0.0.2

func (e *CodeStrLit) Value() string

Value returns the body of the code-string with the fences removed and, for the block form, the common (minimum) body indentation stripped from each line.

func (*CodeStrLit) WriteCode added in v0.0.2

func (e *CodeStrLit) WriteCode(ctx *CodeWriteContext)

type CodeWriteContext

type CodeWriteContext struct {
	Stack  []ast.Node
	Depth  int
	Prefix string
	Flags  CodeWriteContextFlag
	// MaxColumns is the line-width budget for the NEW_LINE_CALC mode (0 uses
	// DefaultMaxColumns).
	MaxColumns int
	Transpile  *TranspileOptions
	CodeWriter
	// contains filtered or unexported fields
}

func NewCodeWriteContext

func NewCodeWriteContext(codeWriter CodeWriter, opt ...CodeOption) *CodeWriteContext

func (CodeWriteContext) Buffer

func (ctx CodeWriteContext) Buffer(do func(ctx *CodeWriteContext)) string

func (*CodeWriteContext) Column added in v0.0.2

func (ctx *CodeWriteContext) Column() int

Column returns the current cursor column (0 when unknown).

func (*CodeWriteContext) CurrentPrefix

func (ctx *CodeWriteContext) CurrentPrefix() string

func (*CodeWriteContext) DecideNewLine added in v0.0.2

func (ctx *CodeWriteContext) DecideNewLine(flag CodeWriteContextFlag, count int, inlineSep string, closing int, do func(i int)) bool

DecideNewLine reports whether a list construct's items should be written one per line. Without NEW_LINE_CALC it honours the per-construct force `flag`. With NEW_LINE_CALC it renders the items inline (separated by inlineSep) and wraps only when they would overflow MaxColumns (or already contain a newline). `closing` is the width of the trailing delimiter (e.g. 1 for `)`).

func (*CodeWriteContext) DecideNewLineFunc added in v0.0.2

func (ctx *CodeWriteContext) DecideNewLineFunc(flag CodeWriteContextFlag, count, closing int, renderInline func()) bool

DecideNewLineFunc is DecideNewLine for constructs whose inline form does not map to a uniform per-item callback: renderInline writes the whole inline body (to a throwaway writer during measurement).

func (*CodeWriteContext) HasPrefix added in v0.0.2

func (ctx *CodeWriteContext) HasPrefix() bool

func (*CodeWriteContext) Pop

func (ctx *CodeWriteContext) Pop()

func (*CodeWriteContext) PrevPrefix

func (ctx *CodeWriteContext) PrevPrefix() string

func (*CodeWriteContext) Printf

func (ctx *CodeWriteContext) Printf(format string, args ...interface{})

func (*CodeWriteContext) Push

func (ctx *CodeWriteContext) Push(n ast.Node)

func (*CodeWriteContext) Top

func (ctx *CodeWriteContext) Top() ast.Node

func (*CodeWriteContext) With

func (ctx *CodeWriteContext) With(n ast.Node, cb func() error) (err error)

func (CodeWriteContext) WithoutPrefix

func (ctx CodeWriteContext) WithoutPrefix() *CodeWriteContext

func (*CodeWriteContext) WriteExprs

func (ctx *CodeWriteContext) WriteExprs(sep string, expr ...Expr)

func (*CodeWriteContext) WriteGreedy added in v0.0.2

func (ctx *CodeWriteContext) WriteGreedy(count int, itemSep, breakConnector string, do func(i int))

WriteGreedy renders count items using the column-aware overflow rule: items are packed onto the current line with itemSep between them and continue on a new line only when the next item would overflow MaxColumns. breakConnector is appended to the line just before a wrap newline (e.g. "" to drop a comma, or " |" to keep a union bar). Continuation lines are written at the current ctx.Depth, so a caller wanting an extra indent level bumps Depth before calling. The caller positions the cursor for item 0 (this writes no leading newline).

func (*CodeWriteContext) WriteItems added in v0.0.2

func (ctx *CodeWriteContext) WriteItems(inNewLine bool, count int, do func(i int), done func(newLine bool))

func (*CodeWriteContext) WriteItemsSep added in v0.0.2

func (ctx *CodeWriteContext) WriteItemsSep(inNewLine bool, count int, inlineSep, newLineSep string, do func(i int), done func(newLine bool))

func (*CodeWriteContext) WriteLeadDoc added in v0.0.2

func (ctx *CodeWriteContext) WriteLeadDoc(g *ast.CommentGroup) bool

WriteLeadDoc emits g as a lead doc — the documented construct follows on its own (prefixed) line — when g has been claimed for node-based emission. It returns true when it emitted the doc. Nodes call this at the start of their WriteCode so the doc travels with the node.

func (*CodeWriteContext) WriteLine

func (ctx *CodeWriteContext) WriteLine(s string)

func (*CodeWriteContext) WritePrefix

func (ctx *CodeWriteContext) WritePrefix()

func (*CodeWriteContext) WritePrefixedLine

func (ctx *CodeWriteContext) WritePrefixedLine()

func (*CodeWriteContext) WritePrevPrefix

func (ctx *CodeWriteContext) WritePrevPrefix()

func (*CodeWriteContext) WriteSecondLine

func (ctx *CodeWriteContext) WriteSecondLine()

func (*CodeWriteContext) WriteSemi

func (ctx *CodeWriteContext) WriteSemi()

func (*CodeWriteContext) WriteSemiOrDoubleLine

func (ctx *CodeWriteContext) WriteSemiOrDoubleLine()

func (*CodeWriteContext) WriteStmts

func (ctx *CodeWriteContext) WriteStmts(stmt ...Stmt)

func (*CodeWriteContext) WriteTrailingDoc added in v0.0.2

func (ctx *CodeWriteContext) WriteTrailingDoc(g *ast.CommentGroup) bool

WriteTrailingDoc emits g as a trailing inline doc (` /// …`) on the current line when g is a claimed doc. Inline docs are kept on one line regardless of width. Returns true when it emitted the doc.

type CodeWriteContextFlag added in v0.0.2

type CodeWriteContextFlag uint16
const (
	CodeWriteContextFlagNone CodeWriteContextFlag = 1 << iota
	CodeWriteContextFlagFormatArrayItemInNewLine
	CodeWriteContextFlagFormatDictItemInNewLine
	CodeWriteContextFlagFormatKeyValueArrayItemInNewLine
	CodeWriteContextFlagFormatCallParamsInNewLine
	CodeWriteContextFlagFormatParemValuesInNewLine
	CodeWriteContextFlagFormatDeclItemInNewLine
	CodeWriteContextFlagFormatMatchExprArmsInNewLine
	CodeWriteContextFlagFormatMatchStmtArmsInNewLine
	CodeWriteContextFlagFormatMethodInterfaceInNewLine
	// CodeWriteContextFlagFormatNewLineCalc (NEW_LINE_CALC) switches the
	// formatter from "force all to new lines" to column-aware wrapping: a list
	// construct stays inline unless it would overflow ctx.MaxColumns. It is not
	// part of CodeWriteContextFlagFormat.
	CodeWriteContextFlagFormatNewLineCalc

	CodeWriteContextFlagFormat = CodeWriteContextFlagFormatArrayItemInNewLine |
		CodeWriteContextFlagFormatDictItemInNewLine |
		CodeWriteContextFlagFormatKeyValueArrayItemInNewLine |
		CodeWriteContextFlagFormatCallParamsInNewLine |
		CodeWriteContextFlagFormatParemValuesInNewLine |
		CodeWriteContextFlagFormatDeclItemInNewLine |
		CodeWriteContextFlagFormatMatchExprArmsInNewLine |
		CodeWriteContextFlagFormatMatchStmtArmsInNewLine |
		CodeWriteContextFlagFormatMethodInterfaceInNewLine
)

func (*CodeWriteContextFlag) Clear added in v0.0.2

func (CodeWriteContextFlag) Has added in v0.0.2

func (*CodeWriteContextFlag) Set added in v0.0.2

func (*CodeWriteContextFlag) Toggle added in v0.0.2

type CodeWriteSkiper added in v0.0.2

type CodeWriteSkiper interface {
	SkipCode(ctx *CodeWriteContext) bool
}

type CodeWriter

type CodeWriter interface {
	io.Writer
	WriteString(s ...string)
	WriteSingleByte(b byte)
	WriteRune(b rune)
	WriteLine(s ...string)
	WriteLines(l ...string)
}

func NewCodeWriter

func NewCodeWriter(w io.Writer) CodeWriter

type Coder

type Coder interface {
	WriteCode(ctx *CodeWriteContext)
}

type ComprehensionClause added in v0.0.2

type ComprehensionClause struct {
	For      bool
	Key      *IdentExpr // for k, v in ...; nil when only a value var is given
	Value    *IdentExpr // for v in ...
	Iterable Expr
	Cond     Expr // if cond
}

ComprehensionClause is one clause of a comprehension: a `for k, v in iter` generator (For == true) or an `if cond` filter (For == false).

func (*ComprehensionClause) String added in v0.0.2

func (c *ComprehensionClause) String() string

func (*ComprehensionClause) WriteCode added in v0.0.2

func (c *ComprehensionClause) WriteCode(ctx *CodeWriteContext)

type ComputedExpr added in v0.0.2

type ComputedExpr struct {
	StartPos source.Pos
	EndPos   source.Pos
	Stmts    Stmts
}

func EComputed added in v0.0.2

func EComputed(start, end source.Pos, stmts ...Stmt) *ComputedExpr

func (*ComputedExpr) End added in v0.0.2

func (e *ComputedExpr) End() source.Pos

func (*ComputedExpr) ExprNode added in v0.0.2

func (e *ComputedExpr) ExprNode()

func (*ComputedExpr) Pos added in v0.0.2

func (e *ComputedExpr) Pos() source.Pos

func (*ComputedExpr) String added in v0.0.2

func (e *ComputedExpr) String() string

func (*ComputedExpr) WriteCode added in v0.0.2

func (e *ComputedExpr) WriteCode(ctx *CodeWriteContext)

type CondExpr

type CondExpr struct {
	Cond        Expr
	True        Expr
	False       Expr
	QuestionPos source.Pos
	ColonPos    source.Pos
}

CondExpr represents a ternary conditional expression.

func ECond

func ECond(
	cond, trueExpr, falseExpr Expr,
	questionPos, colonPos source.Pos,
) *CondExpr

func (*CondExpr) End

func (e *CondExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*CondExpr) ExprNode

func (e *CondExpr) ExprNode()

func (*CondExpr) Pos

func (e *CondExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CondExpr) String

func (e *CondExpr) String() string

func (*CondExpr) WriteCode

func (e *CondExpr) WriteCode(ctx *CodeWriteContext)

type ConfigOptions

type ConfigOptions struct {
	Mixed      bool
	NoMixed    bool
	MixedStart string
	MixedEnd   string
}

type ConfigStmt

type ConfigStmt struct {
	ConfigPos source.Pos
	Elements  []*KeyValuePairLit
	Options   ConfigOptions
}

func SConfig

func SConfig(start source.Pos, opts ...*KeyValuePairLit) *ConfigStmt

func (*ConfigStmt) End

func (c *ConfigStmt) End() source.Pos

func (*ConfigStmt) ParseElements

func (c *ConfigStmt) ParseElements()

func (*ConfigStmt) Pos

func (c *ConfigStmt) Pos() source.Pos

func (*ConfigStmt) SkipCode added in v0.0.2

func (c *ConfigStmt) SkipCode(ctx *CodeWriteContext) bool

func (*ConfigStmt) StmtNode

func (c *ConfigStmt) StmtNode()

func (*ConfigStmt) String

func (c *ConfigStmt) String() string

func (*ConfigStmt) WriteCode

func (c *ConfigStmt) WriteCode(ctx *CodeWriteContext)

type DateTimeLit added in v0.0.2

type DateTimeLit struct {
	// ValuePos is the position of the first digit.
	ValuePos source.Pos
	// Body is the numeric literal without the suffix letter.
	Body string
	// Kind selects the date/time/unix interpretation.
	Kind DateTimeLitKind
}

DateTimeLit is a digit-suffix date/time literal: `20260131D` (date), `235955T` (time) or `1781609136U` (unix time). Body holds the numeric body without the suffix letter; it folds to a date or time value at compile time.

func (*DateTimeLit) End added in v0.0.2

func (e *DateTimeLit) End() source.Pos

End returns the position immediately after the suffix letter.

func (*DateTimeLit) ExprNode added in v0.0.2

func (e *DateTimeLit) ExprNode()

func (*DateTimeLit) Pos added in v0.0.2

func (e *DateTimeLit) Pos() source.Pos

Pos returns the position of the first digit.

func (*DateTimeLit) String added in v0.0.2

func (e *DateTimeLit) String() string

func (*DateTimeLit) WriteCode added in v0.0.2

func (e *DateTimeLit) WriteCode(ctx *CodeWriteContext)

type DateTimeLitKind added in v0.0.2

type DateTimeLitKind uint8

DateTimeLitKind discriminates the digit-suffix date/time literal forms.

const (
	// CalendarDateLitKind is a `2006-01-02D` calendar-date literal.
	CalendarDateLitKind DateTimeLitKind = iota
	// TimeLitKind is a `2006-01-02T` time literal (midnight UTC, zoned).
	TimeLitKind
	// CalendarTimeLitKind is a `2006-01-02t` zone-less calendar-time literal.
	CalendarTimeLitKind
	// UnixTimeLitKind is a unix-seconds literal with a `U` suffix.
	UnixTimeLitKind
)

func (DateTimeLitKind) Suffix added in v0.0.2

func (k DateTimeLitKind) Suffix() string

Suffix returns the source suffix letter for the kind.

type DecimalLit

type DecimalLit struct {
	Value    decimal.Decimal
	ValuePos source.Pos
	Literal  string
}

DecimalLit represents a floating point literal.

func Decimal

func Decimal(value string, pos source.Pos) *DecimalLit

func (*DecimalLit) End

func (e *DecimalLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*DecimalLit) ExprNode

func (e *DecimalLit) ExprNode()

func (*DecimalLit) Pos

func (e *DecimalLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DecimalLit) String

func (e *DecimalLit) String() string

func (*DecimalLit) WriteCode

func (e *DecimalLit) WriteCode(ctx *CodeWriteContext)

type Decl

type Decl interface {
	ast.Node

	Coder
	// contains filtered or unexported methods
}

Decl wraps methods for all declaration nodes.

func NewGenDecl

func NewGenDecl(
	tok token.Token,
	tokPos, lparen, rparen source.Pos,
	specs ...Spec,
) Decl

type DeclStmt

type DeclStmt struct {
	Decl // *GenDecl with VAR token
}

A DeclStmt node represents a declaration in a statement list.

func SDecl

func SDecl(decl Decl) *DeclStmt

func (*DeclStmt) StmtNode

func (*DeclStmt) StmtNode()

type DeferStmt added in v0.0.2

type DeferStmt struct {
	DeferPos source.Pos
	Variant  DeferVariant
	Body     *BlockStmt
	Call     Expr
	// Block reports a `deferb*` statement, which runs at the end of the
	// enclosing block instead of the enclosing function.
	Block bool
	// Inline reports that Body holds a single braceless shortcut statement
	// (e.g. `defer x += 1`), rendered without surrounding braces.
	Inline bool
}

DeferStmt represents a `defer`, `defer_ok` or `defer_err` statement. Exactly one of Body (`defer { ... }`) or Call (`defer handler` / `defer handler(x)`) is set. The handler runs when the enclosing function returns; inside it the locals `$ret` (return value) and `$err` (caught error) are available and may be modified.

func (*DeferStmt) End added in v0.0.2

func (s *DeferStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*DeferStmt) Keyword added in v0.0.2

func (s *DeferStmt) Keyword() string

Keyword returns the source keyword for this statement (defer / defer_ok / deferb_err / ...).

func (*DeferStmt) Pos added in v0.0.2

func (s *DeferStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DeferStmt) StmtNode added in v0.0.2

func (s *DeferStmt) StmtNode()

func (*DeferStmt) String added in v0.0.2

func (s *DeferStmt) String() string

func (*DeferStmt) WriteCode added in v0.0.2

func (s *DeferStmt) WriteCode(ctx *CodeWriteContext)

type DeferVariant added in v0.0.2

type DeferVariant int

DeferVariant selects when a deferred handler runs.

const (
	DeferAlways DeferVariant = iota // defer
	DeferOnOk                       // defer_ok: only when no error
	DeferOnErr                      // defer_err: only when an error occurred
)

func (DeferVariant) String added in v0.0.2

func (v DeferVariant) String() string

type DictComprehension added in v0.0.2

type DictComprehension struct {
	LBrace   source.Pos
	Elements []*DictElementLit
	Clauses  []*ComprehensionClause
	RBrace   source.Pos
}

DictComprehension represents `{k1: v1, [ke]: ve, ... for x in it if cond}`. Each iteration assigns every element into the dict being built; element keys may be static (`name:`) or computed (`[expr]:`). Inside value expressions the special variable `_` refers to the dict being built.

func (*DictComprehension) End added in v0.0.2

func (e *DictComprehension) End() source.Pos

End returns the position of first character immediately after the node.

func (*DictComprehension) ExprNode added in v0.0.2

func (e *DictComprehension) ExprNode()

func (*DictComprehension) Pos added in v0.0.2

func (e *DictComprehension) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DictComprehension) String added in v0.0.2

func (e *DictComprehension) String() string

func (*DictComprehension) WriteCode added in v0.0.2

func (e *DictComprehension) WriteCode(ctx *CodeWriteContext)

type DictElementFuncExprs added in v0.0.2

type DictElementFuncExprs []*FuncDefLit

func (DictElementFuncExprs) Sort added in v0.0.2

func (l DictElementFuncExprs) Sort()

type DictElementLit

type DictElementLit struct {
	Key      Expr
	ColonPos source.Pos
	Value    Expr
	// Spread, when set, marks a `*expr` merge element (`{a:1, *b}`); Key and
	// Value are nil in that case.
	Spread Expr
	Doc    *ast.CommentGroup // doc comment preceding the element; or nil
}

DictElementLit represents a map element.

func EDictElement added in v0.0.2

func EDictElement(key Expr, colonPos source.Pos, value Expr) *DictElementLit

func EDictElementStr added in v0.0.2

func EDictElementStr(key string, keyPos, colonPos source.Pos, value Expr) *DictElementLit

func (*DictElementLit) BuildKeyExpr added in v0.0.2

func (e *DictElementLit) BuildKeyExpr() Expr

func (*DictElementLit) End

func (e *DictElementLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*DictElementLit) ExprNode

func (e *DictElementLit) ExprNode()

func (*DictElementLit) Func

func (e *DictElementLit) Func() (f *FuncDefLit)

func (*DictElementLit) IsFunc

func (e *DictElementLit) IsFunc() (ok bool)

func (*DictElementLit) Pos

func (e *DictElementLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DictElementLit) String

func (e *DictElementLit) String() string

func (*DictElementLit) WriteCode

func (e *DictElementLit) WriteCode(ctx *CodeWriteContext)

type DictExpr

type DictExpr struct {
	LBrace   source.Pos
	Elements []*DictElementLit
	RBrace   source.Pos
}

DictExpr represents a map literal.

func EDict

func EDict(lbrace, rbrace source.Pos, list ...*DictElementLit) *DictExpr

func (*DictExpr) End

func (e *DictExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*DictExpr) ExprNode

func (e *DictExpr) ExprNode()

func (*DictExpr) Pos

func (e *DictExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DictExpr) String

func (e *DictExpr) String() string

func (*DictExpr) WriteCode

func (e *DictExpr) WriteCode(ctx *CodeWriteContext)

type DotFileLit

type DotFileLit struct {
	TokenPos source.Pos
}

DotFileLit represents an @name literal.

func (*DotFileLit) End

func (e *DotFileLit) End() source.Pos

End DotFileLit the position of first character immediately after the node.

func (*DotFileLit) ExprNode

func (e *DotFileLit) ExprNode()

func (*DotFileLit) Pos

func (e *DotFileLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DotFileLit) String

func (e *DotFileLit) String() string

func (*DotFileLit) WriteCode

func (e *DotFileLit) WriteCode(ctx *CodeWriteContext)

type DotFileNameLit

type DotFileNameLit struct {
	TokenPos source.Pos
}

DotFileNameLit represents an @name literal.

func (*DotFileNameLit) End

func (e *DotFileNameLit) End() source.Pos

End DotFileNameLit the position of first character immediately after the node.

func (*DotFileNameLit) ExprNode

func (e *DotFileNameLit) ExprNode()

func (*DotFileNameLit) Pos

func (e *DotFileNameLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DotFileNameLit) String

func (e *DotFileNameLit) String() string

func (*DotFileNameLit) WriteCode

func (e *DotFileNameLit) WriteCode(ctx *CodeWriteContext)

type DurationLit added in v0.0.2

type DurationLit struct {
	// PrefixPos is the position of the `dur` keyword.
	PrefixPos source.Pos
	// Body is the bare duration string (without the `dur ` prefix).
	Body string
}

DurationLit is a `dur 1h25s` duration literal whose body is a bare Go duration string (e.g. "1h30m"). It compiles to a Duration value.

func (*DurationLit) End added in v0.0.2

func (e *DurationLit) End() source.Pos

End returns the position immediately after the duration body.

func (*DurationLit) ExprNode added in v0.0.2

func (e *DurationLit) ExprNode()

func (*DurationLit) Pos added in v0.0.2

func (e *DurationLit) Pos() source.Pos

Pos returns the position of the `dur` keyword.

func (*DurationLit) StrValue added in v0.0.2

func (e *DurationLit) StrValue() string

StrValue returns the duration string content.

func (*DurationLit) String added in v0.0.2

func (e *DurationLit) String() string

func (*DurationLit) WriteCode added in v0.0.2

func (e *DurationLit) WriteCode(ctx *CodeWriteContext)

type EmbedExpr

type EmbedExpr struct {
	Args     CallArgs
	Token    token.Token
	TokenPos source.Pos
}

EmbedExpr represents an embed expression that embeds external files or directories into the compiled program at compile time. It resolves to an EmbeddedNodeFS at runtime.

Syntax: embed(path [; namedParams...])

The path must be a single string or symbol literal specifying the file or directory to embed.

Named parameters (all optional):

  • sources: array of string/symbol literals specifying source paths
  • includes: array of string/symbol literals for file inclusion patterns
  • excludes: array of string/symbol literals for file exclusion patterns
  • includes_re: array of string/symbol literals for regex file inclusion patterns
  • excludes_re: array of string/symbol literals for regex file exclusion patterns
  • config_file: string/symbol literal pointing to a YAML config file with the above named params
  • tree: flag (no value) to embed directory tree recursively

Example:

embed("file.txt")
embed("dir"; tree)
embed("dir"; includes=["*.go"], excludes=["*_test.go"])
embed("dir"; sources=["a", "b"], tree)
embed("dir"; config_file="embed.yaml")

func EEmbed

func EEmbed(args *CallArgs, pos source.Pos) *EmbedExpr

func (*EmbedExpr) ConfigFile added in v0.0.2

func (e *EmbedExpr) ConfigFile() string

ConfigFile returns the config file path from the "config_file" named parameter.

func (*EmbedExpr) End

func (e *EmbedExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*EmbedExpr) Excludes added in v0.0.2

func (e *EmbedExpr) Excludes() []string

Excludes returns the list of exclusion patterns from the "excludes" named parameter.

func (*EmbedExpr) ExcludesRe added in v0.0.2

func (e *EmbedExpr) ExcludesRe() []string

ExcludesRe returns the list of regex exclusion patterns from the "excludes_re" named parameter.

func (*EmbedExpr) ExprNode

func (e *EmbedExpr) ExprNode()

func (*EmbedExpr) Includes added in v0.0.2

func (e *EmbedExpr) Includes() []string

Includes returns the list of inclusion patterns from the "includes" named parameter.

func (*EmbedExpr) IncludesRe added in v0.0.2

func (e *EmbedExpr) IncludesRe() []string

IncludesRe returns the list of regex inclusion patterns from the "includes_re" named parameter.

func (*EmbedExpr) Path

func (e *EmbedExpr) Path() (s string)

Path returns the file or directory path specified as the first argument to embed.

func (*EmbedExpr) Pos

func (e *EmbedExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*EmbedExpr) Sources added in v0.0.2

func (e *EmbedExpr) Sources() []string

Sources returns the list of source paths from the "sources" named parameter.

func (*EmbedExpr) String

func (e *EmbedExpr) String() string

func (*EmbedExpr) Tree added in v0.0.2

func (e *EmbedExpr) Tree() bool

Tree returns true if the "tree" flag is set, indicating recursive directory embedding.

func (*EmbedExpr) WriteCode

func (e *EmbedExpr) WriteCode(ctx *CodeWriteContext)

type EmptyStmt

type EmptyStmt struct {
	Semicolon source.Pos
	Implicit  bool
}

EmptyStmt represents an empty statement.

func (*EmptyStmt) End

func (s *EmptyStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*EmptyStmt) StmtNode

func (s *EmptyStmt) StmtNode()

func (*EmptyStmt) String

func (s *EmptyStmt) String() string

func (*EmptyStmt) WriteCode

func (s *EmptyStmt) WriteCode(*CodeWriteContext)

type EnumExpr added in v0.0.2

type EnumExpr struct {
	EnumToken TokenLit
	NameExpr  Expr
	Fields    []*EnumFieldExpr
	LBrace    source.Pos
	RBrace    source.Pos
	Doc       *ast.CommentGroup // doc comment preceding the enum; or nil
}

EnumExpr is an enum literal: `enum [Name] { field, … }`. It compiles to an Enum constant whose field values are computed at compile time (incrementing integers by default, bit flags under `bit`, or explicit expressions). NameExpr is nil for an anonymous, expression-form enum.

func (*EnumExpr) End added in v0.0.2

func (e *EnumExpr) End() source.Pos

func (*EnumExpr) ExprNode added in v0.0.2

func (e *EnumExpr) ExprNode()

func (*EnumExpr) Pos added in v0.0.2

func (e *EnumExpr) Pos() source.Pos

func (*EnumExpr) String added in v0.0.2

func (e *EnumExpr) String() string

func (*EnumExpr) WriteCode added in v0.0.2

func (e *EnumExpr) WriteCode(ctx *CodeWriteContext)

type EnumFieldExpr added in v0.0.2

type EnumFieldExpr struct {
	Bit     bool        // written with a leading `bit`
	Sign    token.Token // token.Add, token.Sub, or token.Illegal for none
	SignPos source.Pos
	Name    *IdentExpr
	Assign  source.Pos
	Value   Expr              // explicit value; nil when defaulted
	Doc     *ast.CommentGroup // doc comment preceding the field; or nil
}

EnumFieldExpr is one field of an enum body: an optional `bit` prefix, an optional `+`/`-` sign, the field Name (`_` is a placeholder that advances the running value but is not added to the enum) and an optional explicit `= Value` (which may reference earlier fields, e.g. `All = Read | Write`).

func (*EnumFieldExpr) End added in v0.0.2

func (e *EnumFieldExpr) End() source.Pos

func (*EnumFieldExpr) ExprNode added in v0.0.2

func (e *EnumFieldExpr) ExprNode()

func (*EnumFieldExpr) Pos added in v0.0.2

func (e *EnumFieldExpr) Pos() source.Pos

func (*EnumFieldExpr) String added in v0.0.2

func (e *EnumFieldExpr) String() string

func (*EnumFieldExpr) WriteCode added in v0.0.2

func (e *EnumFieldExpr) WriteCode(ctx *CodeWriteContext)

type EnumStmt added in v0.0.2

type EnumStmt struct {
	EnumExpr
}

EnumStmt is the statement form `enum Name { … }`. It compiles to `const Name = <enum expression>`.

func (*EnumStmt) StmtNode added in v0.0.2

func (*EnumStmt) StmtNode()

type ExportStmt added in v0.0.2

type ExportStmt struct {
	TokenPos  source.Pos
	KeyExpr   Expr
	ValueExpr Expr
	Doc       *ast.CommentGroup // doc comment preceding the export; or nil
}

func (*ExportStmt) End added in v0.0.2

func (s *ExportStmt) End() source.Pos

func (*ExportStmt) Pos added in v0.0.2

func (s *ExportStmt) Pos() source.Pos

func (*ExportStmt) StmtNode added in v0.0.2

func (s *ExportStmt) StmtNode()

func (*ExportStmt) String added in v0.0.2

func (s *ExportStmt) String() string

func (*ExportStmt) WriteCode added in v0.0.2

func (s *ExportStmt) WriteCode(ctx *CodeWriteContext)

type Expr

type Expr interface {
	Node
	ExprNode()
}

Expr represents an expression node in the AST.

type ExprSelector

type ExprSelector interface {
	Expr
	GetX() Expr
	GetY() Expr
}

type ExprStmt

type ExprStmt struct {
	Expr Expr
}

ExprStmt represents an expression statement.

func SExpr

func SExpr(x Expr) *ExprStmt

func (*ExprStmt) End

func (s *ExprStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ExprStmt) StmtNode

func (s *ExprStmt) StmtNode()

func (*ExprStmt) String

func (s *ExprStmt) String() string

func (*ExprStmt) WriteCode

func (s *ExprStmt) WriteCode(ctx *CodeWriteContext)

type Exprs

type Exprs []Expr

type FinallyStmt

type FinallyStmt struct {
	FinallyPos source.Pos
	Body       *BlockStmt
}

FinallyStmt represents an finally statement.

func SFinally

func SFinally(
	finallyPos source.Pos,
	body *BlockStmt,
) *FinallyStmt

func (*FinallyStmt) End

func (s *FinallyStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*FinallyStmt) Pos

func (s *FinallyStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FinallyStmt) StmtNode

func (s *FinallyStmt) StmtNode()

func (*FinallyStmt) String

func (s *FinallyStmt) String() string

func (*FinallyStmt) WriteCode

func (s *FinallyStmt) WriteCode(ctx *CodeWriteContext)

type FlagLit

type FlagLit struct {
	ValuePos source.Pos
	Literal  string
	Value    bool
}

FlagLit represents a yes literal.

func Flag

func Flag(value bool, pos source.Pos) *FlagLit

func (*FlagLit) Bool

func (e *FlagLit) Bool() bool

func (*FlagLit) End

func (e *FlagLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*FlagLit) ExprNode

func (e *FlagLit) ExprNode()

func (*FlagLit) Pos

func (e *FlagLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FlagLit) String

func (e *FlagLit) String() string

func (*FlagLit) WriteCode

func (e *FlagLit) WriteCode(ctx *CodeWriteContext)

type FloatLit

type FloatLit struct {
	Value    float64
	ValuePos source.Pos
	Literal  string
}

FloatLit represents a floating point literal.

func Float

func Float(value float64, pos source.Pos) *FloatLit

func (*FloatLit) End

func (e *FloatLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*FloatLit) ExprNode

func (e *FloatLit) ExprNode()

func (*FloatLit) Pos

func (e *FloatLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FloatLit) String

func (e *FloatLit) String() string

func (*FloatLit) WriteCode

func (e *FloatLit) WriteCode(ctx *CodeWriteContext)

type ForInStmt

type ForInStmt struct {
	ForPos   source.Pos
	Key      *IdentExpr
	Value    *IdentExpr
	Iterable Expr
	Body     *BlockStmt
	Else     *BlockStmt
}

ForInStmt represents a for-in statement.

func SForIn

func SForIn(
	key, value *IdentExpr,
	seq Expr,
	body *BlockStmt,
	pos source.Pos,
	elseb ...*BlockStmt,
) *ForInStmt

func (*ForInStmt) End

func (s *ForInStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ForInStmt) Pos

func (s *ForInStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ForInStmt) StmtNode

func (s *ForInStmt) StmtNode()

func (*ForInStmt) String

func (s *ForInStmt) String() string

func (*ForInStmt) WriteCode

func (s *ForInStmt) WriteCode(ctx *CodeWriteContext)

type ForStmt

type ForStmt struct {
	ForPos source.Pos
	Init   Stmt
	Cond   Expr
	Post   Stmt
	Body   *BlockStmt
}

ForStmt represents a for statement.

func SFor

func SFor(
	init Stmt,
	cond Expr,
	post Stmt,
	body *BlockStmt,
	pos source.Pos,
) *ForStmt

func (*ForStmt) End

func (s *ForStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ForStmt) Pos

func (s *ForStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ForStmt) StmtNode

func (s *ForStmt) StmtNode()

func (*ForStmt) String

func (s *ForStmt) String() string

func (*ForStmt) WriteCode

func (s *ForStmt) WriteCode(ctx *CodeWriteContext)

type FuncDefLit added in v0.0.2

type FuncDefLit struct {
	Expr
}

func EDictElementClosure

func EDictElementClosure(c *ClosureExpr) *FuncDefLit

func EDictElementFunc

func EDictElementFunc(f *FuncExpr) *FuncDefLit

func (*FuncDefLit) Closure added in v0.0.2

func (e *FuncDefLit) Closure() (c *ClosureExpr)

func (*FuncDefLit) Func added in v0.0.2

func (e *FuncDefLit) Func() (f *FuncExpr)

func (*FuncDefLit) Params added in v0.0.2

func (e *FuncDefLit) Params() *FuncParams

type FuncExpr

type FuncExpr struct {
	Type      *FuncType
	Body      *BlockStmt
	LambdaPos source.Pos
	BodyExpr  Expr
	Doc       *ast.CommentGroup // associated doc comment (`/?`, `/??`, `/???`); or nil
	// Override reports whether a `met` declaration was written `met ~name(…)`,
	// so re-adding an existing method signature replaces it instead of erroring.
	Override bool
}

FuncExpr represents a function literal.

func EFunc

func EFunc(funcType *FuncType, body *BlockStmt) *FuncExpr

func EFuncBodyE

func EFuncBodyE(funcType *FuncType, lambdaPos source.Pos, body Expr) *FuncExpr

func (*FuncExpr) End

func (e *FuncExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncExpr) ExprNode

func (e *FuncExpr) ExprNode()

func (*FuncExpr) Pos

func (e *FuncExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncExpr) String

func (e *FuncExpr) String() string

func (*FuncExpr) WriteCode

func (e *FuncExpr) WriteCode(ctx *CodeWriteContext)

type FuncHeader added in v0.0.2

type FuncHeader struct {
	NameExpr Expr
	Params   FuncParams
	Return   []*TypedIdentExpr
}

FuncHeader is the shared shape of a function/method signature: an optional name, a parameter list and an optional return-type list. It is embedded in FuncType and FuncHeaderExpr.

func (*FuncHeader) End added in v0.0.2

func (e *FuncHeader) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncHeader) Name added in v0.0.2

func (e *FuncHeader) Name() string

func (*FuncHeader) NameIdent added in v0.0.2

func (e *FuncHeader) NameIdent() *IdentExpr

func (*FuncHeader) Pos added in v0.0.2

func (e *FuncHeader) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncHeader) String added in v0.0.2

func (e *FuncHeader) String() string

func (*FuncHeader) WriteCode added in v0.0.2

func (e *FuncHeader) WriteCode(ctx *CodeWriteContext)

WriteCode renders the header (name + params + return) routing the parameter list through FuncParams.WriteCode so it participates in formatting.

type FuncHeaderExpr added in v0.0.2

type FuncHeaderExpr struct {
	OpenPos  source.Pos        // `<`
	ClosePos source.Pos        // `>`
	Doc      *ast.CommentGroup // doc comment preceding the header (in a meti); or nil
	FuncHeader
}

FuncHeaderExpr is a function-header value expression written between angle brackets: `<()>`, `<(v int)>`, `<(v int) <x uint|int>>`. It evaluates to a FunctionHeader value describing a signature.

func (*FuncHeaderExpr) End added in v0.0.2

func (e *FuncHeaderExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncHeaderExpr) ExprNode added in v0.0.2

func (e *FuncHeaderExpr) ExprNode()

func (*FuncHeaderExpr) Pos added in v0.0.2

func (e *FuncHeaderExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncHeaderExpr) String added in v0.0.2

func (e *FuncHeaderExpr) String() string

func (*FuncHeaderExpr) WriteCode added in v0.0.2

func (e *FuncHeaderExpr) WriteCode(ctx *CodeWriteContext)

type FuncMethod added in v0.0.2

type FuncMethod struct {
	Params    FuncParams
	Return    []*TypedIdentExpr
	Body      *BlockStmt
	LambdaPos source.Pos
	BodyExpr  Expr
	Doc       *ast.CommentGroup // doc comment preceding the method header; or nil
	// Override reports whether the method header was prefixed with `~`, so
	// re-adding an existing signature replaces it instead of erroring.
	Override bool
}

func (*FuncMethod) End added in v0.0.2

func (m *FuncMethod) End() source.Pos

func (*FuncMethod) Func added in v0.0.2

func (m *FuncMethod) Func() *FuncExpr

func (*FuncMethod) Pos added in v0.0.2

func (m *FuncMethod) Pos() source.Pos

func (*FuncMethod) String added in v0.0.2

func (m *FuncMethod) String() string

func (*FuncMethod) WriteCode added in v0.0.2

func (m *FuncMethod) WriteCode(ctx *CodeWriteContext)

type FuncParams

type FuncParams struct {
	LParen    source.Pos
	Args      ArgsList
	NamedArgs NamedArgsList
	RParen    source.Pos
}

FuncParams represents a function paramsw.

func NewFuncParams added in v0.0.2

func NewFuncParams(lparen, rparen source.Pos, v ...any) *FuncParams

func (*FuncParams) Caller

func (n *FuncParams) Caller() (c *CallArgs)

func (*FuncParams) End

func (n *FuncParams) End() (pos source.Pos)

End returns the position of first character immediately after the node.

func (*FuncParams) Pos

func (n *FuncParams) Pos() (pos source.Pos)

Pos returns the position of first character belonging to the node.

func (*FuncParams) String

func (n *FuncParams) String() string

func (FuncParams) WithNamedValuesNil

func (n FuncParams) WithNamedValuesNil() (c *FuncParams)

func (*FuncParams) WriteCode added in v0.0.2

func (n *FuncParams) WriteCode(ctx *CodeWriteContext)

WriteCode renders the parameter list, wrapping one parameter per line when NEW_LINE_CALC decides it overflows (no comma between wrapped items). The named section is introduced by `;`; a typed param keeps its ident and type on one line (each item is a single rendered string).

type FuncStmt added in v0.0.2

type FuncStmt struct {
	Func *FuncExpr
}

func SFunc added in v0.0.2

func SFunc(x *FuncExpr) *FuncStmt

func (*FuncStmt) End added in v0.0.2

func (f *FuncStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncStmt) Pos added in v0.0.2

func (f *FuncStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (FuncStmt) StmtNode added in v0.0.2

func (f FuncStmt) StmtNode()

func (*FuncStmt) String added in v0.0.2

func (f *FuncStmt) String() string

func (*FuncStmt) WriteCode added in v0.0.2

func (f *FuncStmt) WriteCode(ctx *CodeWriteContext)

type FuncType

type FuncType struct {
	Token   TokenLit
	FuncPos source.Pos
	FuncHeader
}

FuncType represents a function type definition.

func NewFuncType

func NewFuncType(pos, lparen, rparen source.Pos, v ...any) *FuncType

func ProxyFuncType

func ProxyFuncType() *FuncType

func (*FuncType) End

func (e *FuncType) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncType) ExprNode

func (e *FuncType) ExprNode()

func (*FuncType) Pos

func (e *FuncType) Pos() source.Pos

Pos returns the position of first character belonging to the node.

type FuncWithMethodsExpr added in v0.0.2

type FuncWithMethodsExpr struct {
	FuncToken TokenLit
	LBrace    source.Pos
	RBrace    source.Pos
	NameExpr  Expr
	Methods   []*FuncMethod
	Doc       *ast.CommentGroup // doc comment preceding the func; or nil
}

FuncWithMethodsExpr represents the function with methods expression.

func (*FuncWithMethodsExpr) End added in v0.0.2

func (e *FuncWithMethodsExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncWithMethodsExpr) ExprNode added in v0.0.2

func (e *FuncWithMethodsExpr) ExprNode()

func (*FuncWithMethodsExpr) Funcs added in v0.0.2

func (e *FuncWithMethodsExpr) Funcs() (f Exprs)

func (*FuncWithMethodsExpr) NameIdent added in v0.0.2

func (e *FuncWithMethodsExpr) NameIdent() *IdentExpr

func (*FuncWithMethodsExpr) Pos added in v0.0.2

func (e *FuncWithMethodsExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncWithMethodsExpr) String added in v0.0.2

func (e *FuncWithMethodsExpr) String() string

func (*FuncWithMethodsExpr) WriteCode added in v0.0.2

func (e *FuncWithMethodsExpr) WriteCode(ctx *CodeWriteContext)

type FuncWithMethodsStmt added in v0.0.2

type FuncWithMethodsStmt struct {
	FuncWithMethodsExpr
}

func (FuncWithMethodsStmt) StmtNode added in v0.0.2

func (f FuncWithMethodsStmt) StmtNode()

type GenDecl

type GenDecl struct {
	TokPos source.Pos  // position of Tok
	Tok    token.Token // Var
	Lparen source.Pos  // position of '(', if any
	Specs  []Spec
	Rparen source.Pos        // position of ')', if any
	Doc    *ast.CommentGroup // associated doc comment (`/?`, `/??`, `/???`); or nil
}

A GenDecl node (generic declaration node) represents a variable declaration. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.

Relationship between Tok value and Specs element type:

token.Var     *ValueSpec

func (*GenDecl) End

func (d *GenDecl) End() source.Pos

End returns the position of first character immediately after the node.

func (*GenDecl) Params added in v0.0.2

func (d *GenDecl) Params() (positional []*ParamSpec, named []*NamedParamSpec)

func (*GenDecl) Pos

func (d *GenDecl) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*GenDecl) String

func (d *GenDecl) String() string

func (*GenDecl) WriteCode

func (d *GenDecl) WriteCode(ctx *CodeWriteContext)

type GlobalsLit added in v0.0.2

type GlobalsLit struct {
	TokenPos source.Pos
}

GlobalsLit is the `@g` keyword: a short form of the `globals()` builtin call that yields the host-provided globals object.

func (*GlobalsLit) End added in v0.0.2

func (e *GlobalsLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*GlobalsLit) ExprNode added in v0.0.2

func (e *GlobalsLit) ExprNode()

func (*GlobalsLit) Pos added in v0.0.2

func (e *GlobalsLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*GlobalsLit) String added in v0.0.2

func (e *GlobalsLit) String() string

func (*GlobalsLit) WriteCode added in v0.0.2

func (e *GlobalsLit) WriteCode(ctx *CodeWriteContext)

type HeredocLit added in v0.0.2

type HeredocLit struct {
	Literal    string
	LiteralPos source.Pos
}

HeredocLit represents a non-raw heredoc string literal delimited by a fence of three or more double quotes (`"""`). It shares RawHeredocLit's fencing, opening-line and common-indentation handling, but, like a double-quoted StrLit, it interprets escape sequences (e.g. \n, \t, \", \xFF, \uXXXX) in its content.

func Heredoc added in v0.0.2

func Heredoc(value string, pos source.Pos) *HeredocLit

func (*HeredocLit) ContentPos added in v0.0.2

func (e *HeredocLit) ContentPos() source.Pos

ContentPos returns the source position of the first byte of RawContent.

func (*HeredocLit) End added in v0.0.2

func (e *HeredocLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*HeredocLit) ExprNode added in v0.0.2

func (e *HeredocLit) ExprNode()

func (*HeredocLit) Pos added in v0.0.2

func (e *HeredocLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*HeredocLit) RawContent added in v0.0.2

func (e *HeredocLit) RawContent() string

RawContent returns the heredoc body with the surrounding quote fences, the opening fence line and the closing line removed, but with interior indentation preserved and escape sequences left unprocessed. It keeps a 1:1 byte correspondence with the original source starting at ContentPos.

func (*HeredocLit) String added in v0.0.2

func (e *HeredocLit) String() string

func (*HeredocLit) StripCount added in v0.0.2

func (e *HeredocLit) StripCount() int

StripCount returns the common leading indentation (spaces/tabs) removed from each content line by Value. It is zero for the single-line form (no newline after the opening fence), which is not indentation-stripped.

func (*HeredocLit) Value added in v0.0.2

func (e *HeredocLit) Value() string

func (*HeredocLit) WriteCode added in v0.0.2

func (e *HeredocLit) WriteCode(ctx *CodeWriteContext)

type IdentExpr

type IdentExpr struct {
	Name    string
	NamePos source.Pos
	Empty   bool
}

IdentExpr represents an identifier.

func EEmptyIdent

func EEmptyIdent(pos source.Pos) *IdentExpr

func EIdent

func EIdent(name string, pos source.Pos) *IdentExpr

func IdentOfSelector added in v0.0.2

func IdentOfSelector(x Expr) (ident *IdentExpr)

func (*IdentExpr) End

func (e *IdentExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*IdentExpr) ExprNode

func (e *IdentExpr) ExprNode()

func (*IdentExpr) Pos

func (e *IdentExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IdentExpr) String

func (e *IdentExpr) String() string

func (*IdentExpr) WriteCode

func (e *IdentExpr) WriteCode(ctx *CodeWriteContext)

type IdentList

type IdentList struct {
	LParen  source.Pos
	VarArgs bool
	List    []*IdentExpr
	RParen  source.Pos
}

IdentList represents a list of identifiers.

func (*IdentList) End

func (n *IdentList) End() source.Pos

End returns the position of first character immediately after the node.

func (*IdentList) NumFields

func (n *IdentList) NumFields() int

NumFields returns the number of fields.

func (*IdentList) Pos

func (n *IdentList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IdentList) String

func (n *IdentList) String() string

type IfStmt

type IfStmt struct {
	IfPos source.Pos
	Init  Stmt
	Cond  Expr
	Body  *BlockStmt
	Else  Stmt // else branch; or nil
}

IfStmt represents an if statement.

func SIf

func SIf(
	init Stmt,
	cond Expr,
	body *BlockStmt,
	elseStmt Stmt,
	pos source.Pos,
) *IfStmt

func (*IfStmt) End

func (s *IfStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*IfStmt) Pos

func (s *IfStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IfStmt) StmtNode

func (s *IfStmt) StmtNode()

func (*IfStmt) String

func (s *IfStmt) String() string

func (*IfStmt) WriteCode

func (s *IfStmt) WriteCode(ctx *CodeWriteContext)

type ImportExpr

type ImportExpr struct {
	CallExpr
}

ImportExpr represents an import expression

func EImport

func EImport(pos source.Pos, moduleName string, lparen, rparen, moduleNamePos source.Pos) *ImportExpr

func (*ImportExpr) Build added in v0.0.2

func (e *ImportExpr) Build() (moduleName string, args CallArgs)

func (*ImportExpr) ExprNode

func (e *ImportExpr) ExprNode()

func (*ImportExpr) ModuleName

func (e *ImportExpr) ModuleName() string

func (*ImportExpr) WriteCode

func (e *ImportExpr) WriteCode(ctx *CodeWriteContext)

type IncDecStmt

type IncDecStmt struct {
	Expr     Expr
	Token    token.Token
	TokenPos source.Pos
}

IncDecStmt represents increment or decrement statement.

func SIncDec

func SIncDec(
	expr Expr,
	tok token.Token,
	pos source.Pos,
) *IncDecStmt

func (*IncDecStmt) End

func (s *IncDecStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*IncDecStmt) Pos

func (s *IncDecStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IncDecStmt) StmtNode

func (s *IncDecStmt) StmtNode()

func (*IncDecStmt) String

func (s *IncDecStmt) String() string

func (*IncDecStmt) WriteCode

func (s *IncDecStmt) WriteCode(ctx *CodeWriteContext)

type IndexExpr

type IndexExpr struct {
	X      Expr
	LBrack source.Pos
	Index  Expr
	RBrack source.Pos
}

IndexExpr represents an index expression.

func EIndex

func EIndex(
	x, index Expr,
	lbrack, rbrack source.Pos,
) *IndexExpr

func (*IndexExpr) End

func (e *IndexExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*IndexExpr) ExprNode

func (e *IndexExpr) ExprNode()

func (*IndexExpr) GetX added in v0.0.2

func (e *IndexExpr) GetX() Expr

func (*IndexExpr) GetY added in v0.0.2

func (e *IndexExpr) GetY() Expr

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IndexExpr) String

func (e *IndexExpr) String() string

func (*IndexExpr) WriteCode

func (e *IndexExpr) WriteCode(ctx *CodeWriteContext)

type IntLit

type IntLit struct {
	Value    int64
	ValuePos source.Pos
	Literal  string
}

IntLit represents an integer literal.

func Int

func Int(value int64, pos source.Pos) *IntLit

func (*IntLit) End

func (e *IntLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*IntLit) ExprNode

func (e *IntLit) ExprNode()

func (*IntLit) Pos

func (e *IntLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IntLit) String

func (e *IntLit) String() string

func (*IntLit) WriteCode

func (e *IntLit) WriteCode(ctx *CodeWriteContext)

type InterfaceExpr added in v0.0.2

type InterfaceExpr struct {
	InterfaceToken TokenLit
	NameExpr       Expr   // *IdentExpr or nil (anonymous)
	Parents        []Expr // *Parent spreads — no alias
	ExtendsDoc     *ast.CommentGroup
	Members        []*InterfaceMemberExpr // fields, getters, setters, props (source order)
	Methods        []*InterfaceMethodExpr // required methods (one or more signatures each)
	LBrace         source.Pos
	RBrace         source.Pos
	Doc            *ast.CommentGroup // doc comment preceding the interface; or nil
}

InterfaceExpr is an interface literal describing a structural contract:

interface [Name] {
  *Parent, …                  // parent interfaces (spread)
  field, field Type          // typed fields
  get g, set s, prop p        // accessors
  method(params) <return>     // required methods (func-header shape)
  parse { (params) <return> } // meti-style headers grouped as `parse`
}

func (*InterfaceExpr) End added in v0.0.2

func (e *InterfaceExpr) End() source.Pos

func (*InterfaceExpr) ExprNode added in v0.0.2

func (e *InterfaceExpr) ExprNode()

func (*InterfaceExpr) NameIdent added in v0.0.2

func (e *InterfaceExpr) NameIdent() *IdentExpr

NameIdent returns the interface name identifier, or nil when anonymous.

func (*InterfaceExpr) Pos added in v0.0.2

func (e *InterfaceExpr) Pos() source.Pos

func (*InterfaceExpr) String added in v0.0.2

func (e *InterfaceExpr) String() string

func (*InterfaceExpr) WriteCode added in v0.0.2

func (e *InterfaceExpr) WriteCode(ctx *CodeWriteContext)

type InterfaceMemberExpr added in v0.0.2

type InterfaceMemberExpr struct {
	Kind  InterfaceMemberKind
	KwPos source.Pos // position of get/set/prop keyword; NoPos for a field
	Name  *TypedIdentExpr
	Doc   *ast.CommentGroup
}

InterfaceMemberExpr is a field/getter/setter/property in an interface body: an optional `get`/`set`/`prop` keyword followed by a typed ident (`name` or `name Type1|Type2`).

func (*InterfaceMemberExpr) End added in v0.0.2

func (e *InterfaceMemberExpr) End() source.Pos

func (*InterfaceMemberExpr) ExprNode added in v0.0.2

func (e *InterfaceMemberExpr) ExprNode()

func (*InterfaceMemberExpr) Pos added in v0.0.2

func (e *InterfaceMemberExpr) Pos() source.Pos

func (*InterfaceMemberExpr) String added in v0.0.2

func (e *InterfaceMemberExpr) String() string

func (*InterfaceMemberExpr) WriteCode added in v0.0.2

func (e *InterfaceMemberExpr) WriteCode(ctx *CodeWriteContext)

type InterfaceMemberKind added in v0.0.2

type InterfaceMemberKind uint8

InterfaceMemberKind selects the kind of a simple (name + optional types) interface body member: a field, or a getter/setter/property accessor.

const (
	// IfaceField is a typed field: `name` or `name Type`.
	IfaceField InterfaceMemberKind = iota
	// IfaceGet is a getter: `get name` or `get name Type`.
	IfaceGet
	// IfaceSet is a setter: `set name` or `set name Type`.
	IfaceSet
	// IfaceProp is a property (getter + setter shortcut): `prop name [Type]`.
	IfaceProp
)

func (InterfaceMemberKind) String added in v0.0.2

func (k InterfaceMemberKind) String() string

type InterfaceMethodExpr added in v0.0.2

type InterfaceMethodExpr struct {
	NameExpr *IdentExpr
	Headers  []*FuncHeaderExpr // the signature(s), anonymous (the name is on NameExpr)
	Block    bool              // written in the brace-block form
	LBrace   source.Pos
	RBrace   source.Pos
	Doc      *ast.CommentGroup
}

InterfaceMethodExpr is a required method of an interface: a name and one or more signatures (func-header shape, without the `<…>` brackets). Written either single `name(params) <return>` or block `name { (params) <return>, … }` (the block form is how the `parse` example groups several signatures).

func (*InterfaceMethodExpr) End added in v0.0.2

func (e *InterfaceMethodExpr) End() source.Pos

func (*InterfaceMethodExpr) ExprNode added in v0.0.2

func (e *InterfaceMethodExpr) ExprNode()

func (*InterfaceMethodExpr) Pos added in v0.0.2

func (e *InterfaceMethodExpr) Pos() source.Pos

func (*InterfaceMethodExpr) String added in v0.0.2

func (e *InterfaceMethodExpr) String() string

func (*InterfaceMethodExpr) WriteCode added in v0.0.2

func (e *InterfaceMethodExpr) WriteCode(ctx *CodeWriteContext)

type InterfaceStmt added in v0.0.2

type InterfaceStmt struct {
	InterfaceExpr
}

InterfaceStmt is the statement form `interface Name { … }`, which binds a const to the interface value.

func (*InterfaceStmt) StmtNode added in v0.0.2

func (s *InterfaceStmt) StmtNode()

type IsMainLit added in v0.0.2

type IsMainLit struct {
	TokenPos source.Pos
}

IsMainLit represents an @main literal.

func (*IsMainLit) End added in v0.0.2

func (e *IsMainLit) End() source.Pos

End IsMainLit the position of first character immediately after the node.

func (*IsMainLit) ExprNode added in v0.0.2

func (e *IsMainLit) ExprNode()

func (*IsMainLit) Pos added in v0.0.2

func (e *IsMainLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IsMainLit) String added in v0.0.2

func (e *IsMainLit) String() string

func (*IsMainLit) WriteCode added in v0.0.2

func (e *IsMainLit) WriteCode(ctx *CodeWriteContext)

type KeyValueArrayLit

type KeyValueArrayLit struct {
	LParen   source.Pos
	Elements Exprs
	RParen   source.Pos
	// Curly marks the TypeScript-style `{ key, key2: target, **rest }`
	// destructuring form (as opposed to the `(; … )` form). It only affects
	// rendering; the elements are stored key-on-the-left (source key in Key,
	// target in Value), which the dict-destructuring compiler reads directly.
	Curly bool
}

KeyValueArrayLit represents a key value array literal.

func (*KeyValueArrayLit) End

func (e *KeyValueArrayLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValueArrayLit) ExprNode

func (e *KeyValueArrayLit) ExprNode()

func (*KeyValueArrayLit) Pos

func (e *KeyValueArrayLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValueArrayLit) String

func (e *KeyValueArrayLit) String() string

func (*KeyValueArrayLit) ToMultiParenExpr

func (e *KeyValueArrayLit) ToMultiParenExpr() *MultiParenExpr

func (*KeyValueArrayLit) WriteCode

func (e *KeyValueArrayLit) WriteCode(ctx *CodeWriteContext)

type KeyValueLit

type KeyValueLit struct {
	Key   Expr
	Value Expr
}

KeyValueLit represents a key value element.

func KV

func KV(key Expr, value ...Expr) *KeyValueLit

func (*KeyValueLit) ElementString

func (e *KeyValueLit) ElementString() string

func (*KeyValueLit) End

func (e *KeyValueLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValueLit) ExprNode

func (e *KeyValueLit) ExprNode()

func (*KeyValueLit) Pos

func (e *KeyValueLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValueLit) String

func (e *KeyValueLit) String() string

func (*KeyValueLit) WriteCode

func (e *KeyValueLit) WriteCode(ctx *CodeWriteContext)

type KeyValuePairLit

type KeyValuePairLit struct {
	Key   Expr
	Value Expr
	// Colon reports that the key and value were separated by ':' instead of
	// '='. It is used by the dict-destructuring target `(;name:key, ...)` where
	// the value names the source dict key to read into the variable `name`.
	Colon bool
}

KeyValuePairLit represents a key value pair element.

func KVp

func KVp(key Expr, value ...Expr) *KeyValuePairLit

func (*KeyValuePairLit) End

func (e *KeyValuePairLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValuePairLit) ExprNode

func (e *KeyValuePairLit) ExprNode()

func (*KeyValuePairLit) Func added in v0.0.2

func (e *KeyValuePairLit) Func() (f *FuncDefLit)

func (*KeyValuePairLit) IsFunc added in v0.0.2

func (e *KeyValuePairLit) IsFunc() (ok bool)

func (*KeyValuePairLit) Pos

func (e *KeyValuePairLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValuePairLit) String

func (e *KeyValuePairLit) String() string

func (*KeyValuePairLit) WriteCode

func (e *KeyValuePairLit) WriteCode(ctx *CodeWriteContext)

type MatchArm added in v0.0.2

type MatchArm struct {
	Conds  []Expr     // conditions (OR); empty for the else arm
	Result Expr       // `conds: result`
	Body   *BlockStmt // `conds { body }`
}

MatchArm is a single arm of a MatchExpr. A normal arm has one or more Conds, matched against the subject with OR semantics (`A, B: …`); the `else` arm has no Conds. Exactly one of Result (expression form `conds: result`) or Body (statement form `conds { body }`) is set.

func (*MatchArm) IsElse added in v0.0.2

func (a *MatchArm) IsElse() bool

IsElse reports whether this arm is the default `else` arm.

func (*MatchArm) String added in v0.0.2

func (a *MatchArm) String() string

func (*MatchArm) WriteCode added in v0.0.2

func (a *MatchArm) WriteCode(ctx *CodeWriteContext)

type MatchExpr added in v0.0.2

type MatchExpr struct {
	MatchPos source.Pos
	Expr     Expr // subject
	Arms     []*MatchArm
	LBrace   source.Pos
	RBrace   source.Pos
}

MatchExpr represents a PHP8-like match: `match subject { cond: result, ... }` (expression form, yields a value) or `match subject { cond { body }, ... }` (statement form, runs the matching block). Each arm holds one or more conditions compared against the subject with strict equality; the first arm with a matching condition wins. An optional `else` arm is the default. When nothing matches and there is no `else`, the match yields nil.

func (*MatchExpr) End added in v0.0.2

func (e *MatchExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*MatchExpr) ExprNode added in v0.0.2

func (e *MatchExpr) ExprNode()

func (*MatchExpr) IsStmt added in v0.0.2

func (e *MatchExpr) IsStmt() bool

IsStmt reports whether the match uses statement-form (block) arms.

func (*MatchExpr) Pos added in v0.0.2

func (e *MatchExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MatchExpr) String added in v0.0.2

func (e *MatchExpr) String() string

func (*MatchExpr) WriteCode added in v0.0.2

func (e *MatchExpr) WriteCode(ctx *CodeWriteContext)

type MethodExpr added in v0.0.2

type MethodExpr struct {
	Expr
}

func EMethod added in v0.0.2

func EMethod(expr *FuncExpr) *MethodExpr

type MethodInterfaceExpr added in v0.0.2

type MethodInterfaceExpr struct {
	MetiToken TokenLit
	NameExpr  Expr
	LBrace    source.Pos
	RBrace    source.Pos
	Headers   []*FuncHeaderExpr
	// Shortcut reports the single-method `meti <header>` form (one header, no
	// braces); it is preserved by WriteCode.
	Shortcut bool
	Doc      *ast.CommentGroup // doc comment preceding the meti; or nil
}

MethodInterfaceExpr is a set of required function headers introduced by the `meti` keyword: `meti { () }`, `meti { (), (v) <int> }`, `meti Name { … }`. Each header is a FuncHeaderExpr written without the surrounding angle brackets.

func (*MethodInterfaceExpr) End added in v0.0.2

func (e *MethodInterfaceExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*MethodInterfaceExpr) ExprNode added in v0.0.2

func (e *MethodInterfaceExpr) ExprNode()

func (*MethodInterfaceExpr) NameIdent added in v0.0.2

func (e *MethodInterfaceExpr) NameIdent() *IdentExpr

func (*MethodInterfaceExpr) Pos added in v0.0.2

func (e *MethodInterfaceExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MethodInterfaceExpr) String added in v0.0.2

func (e *MethodInterfaceExpr) String() string

func (*MethodInterfaceExpr) WriteCode added in v0.0.2

func (e *MethodInterfaceExpr) WriteCode(ctx *CodeWriteContext)

type MethodInterfaceStmt added in v0.0.2

type MethodInterfaceStmt struct {
	MethodInterfaceExpr
}

MethodInterfaceStmt is the statement form of a method interface, e.g. `meti Name { () }`, which binds the interface to a const.

func (MethodInterfaceStmt) StmtNode added in v0.0.2

func (s MethodInterfaceStmt) StmtNode()

type MixedTextExpr

type MixedTextExpr struct {
	StartLit ast.Literal
	EndLit   ast.Literal
	Stmt     MixedTextStmt
}

func (*MixedTextExpr) End

func (e *MixedTextExpr) End() source.Pos

func (*MixedTextExpr) ExprNode

func (e *MixedTextExpr) ExprNode()

func (*MixedTextExpr) Pos

func (e *MixedTextExpr) Pos() source.Pos

func (*MixedTextExpr) String

func (e *MixedTextExpr) String() string

func (*MixedTextExpr) WriteCode

func (e *MixedTextExpr) WriteCode(ctx *CodeWriteContext)

type MixedTextStmt

type MixedTextStmt struct {
	Lit    ast.Literal
	Flags  MixedTextStmtFlag
	LParen source.Pos
	RParen source.Pos
}

MixedTextStmt represents an MixedTextStmt.

func SMixedText

func SMixedText(pos source.Pos, vlit string, flags ...MixedTextStmtFlag) *MixedTextStmt

func (*MixedTextStmt) End

func (s *MixedTextStmt) End() source.Pos

func (*MixedTextStmt) ExprNode

func (s *MixedTextStmt) ExprNode()

func (*MixedTextStmt) Pos

func (s *MixedTextStmt) Pos() source.Pos

func (*MixedTextStmt) StmtNode

func (s *MixedTextStmt) StmtNode()

func (*MixedTextStmt) String

func (s *MixedTextStmt) String() string

func (*MixedTextStmt) TrimLinePrefix

func (s *MixedTextStmt) TrimLinePrefix(prefix string)

func (*MixedTextStmt) ValidLit

func (s *MixedTextStmt) ValidLit() ast.Literal

func (*MixedTextStmt) Value

func (s *MixedTextStmt) Value() string

func (*MixedTextStmt) WriteCode

func (s *MixedTextStmt) WriteCode(ctx *CodeWriteContext)

type MixedTextStmtFlag

type MixedTextStmtFlag uint
const (
	// RemoveLeftSpaces / RemoveRightSpaces are the single-dash markers (`-%}`
	// trims the following text's leading blanks; `{%-` trims the preceding
	// text's trailing blanks) and preserve a single boundary newline.
	RemoveLeftSpaces MixedTextStmtFlag = 1 << iota
	RemoveRightSpaces
	// RemoveLeftAll / RemoveRightAll are the double-dash markers (`--%}` / `{%--`)
	// and strip ALL boundary whitespace, newlines included.
	RemoveLeftAll
	RemoveRightAll
)

func (MixedTextStmtFlag) Has

func (MixedTextStmtFlag) String

func (s MixedTextStmtFlag) String() string

type MixedValueStmt

type MixedValueStmt struct {
	Expr             Expr
	StartLit         ast.Literal
	EndLit           ast.Literal
	RemoveLeftSpace  bool
	RemoveRightSpace bool
	// RemoveLeftAll/RemoveRightAll are the double-dash markers (`{%--= … --%}`)
	// that strip ALL adjacent whitespace (newlines included).
	RemoveLeftAll  bool
	RemoveRightAll bool
	Eq             bool
}

MixedValueStmt is an inline value-emitting tag in mixed/template mode, e.g. `{%= expr %}`, whose Expr is evaluated and written into the surrounding text. StartLit/EndLit hold the opening/closing delimiters (`{%`/`%}`); Eq reports the `=` value marker. RemoveLeftSpace/RemoveRightSpace mirror the `-` trim markers (`{%- … -%}`) that strip surrounding whitespace from the adjacent text at run time.

func SMixedValue

func SMixedValue(start, end ast.Literal, expr Expr) *MixedValueStmt

func (*MixedValueStmt) End

func (s *MixedValueStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*MixedValueStmt) ExprNode

func (s *MixedValueStmt) ExprNode()

func (*MixedValueStmt) Pos

func (s *MixedValueStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MixedValueStmt) StmtNode

func (s *MixedValueStmt) StmtNode()

func (*MixedValueStmt) String

func (s *MixedValueStmt) String() string

func (*MixedValueStmt) WriteCode

func (s *MixedValueStmt) WriteCode(ctx *CodeWriteContext)

type ModuleLit added in v0.0.2

type ModuleLit struct {
	TokenPos source.Pos
}

ModuleLit represents an @module literal.

func LModule added in v0.0.2

func LModule(pos source.Pos) *ModuleLit

func (*ModuleLit) End added in v0.0.2

func (e *ModuleLit) End() source.Pos

End IsMainLit the position of first character immediately after the node.

func (*ModuleLit) ExprNode added in v0.0.2

func (e *ModuleLit) ExprNode()

func (*ModuleLit) Pos added in v0.0.2

func (e *ModuleLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ModuleLit) String added in v0.0.2

func (e *ModuleLit) String() string

func (*ModuleLit) WriteCode added in v0.0.2

func (e *ModuleLit) WriteCode(ctx *CodeWriteContext)

type MultiParenExpr

type MultiParenExpr struct {
	LParen             Token
	RParen             Token
	PositionalElements Exprs
	NamedElements      Exprs
}

MultiParenExpr represents a parenthesis wrapped expressions.

func (*MultiParenExpr) End

func (e *MultiParenExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*MultiParenExpr) ExprNode

func (e *MultiParenExpr) ExprNode()

func (*MultiParenExpr) Pos

func (e *MultiParenExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MultiParenExpr) String

func (e *MultiParenExpr) String() string

func (*MultiParenExpr) ToCallArgs

func (e *MultiParenExpr) ToCallArgs(strict bool) (args *CallArgs, err *NodeError)

func (*MultiParenExpr) ToFuncHeaderParams added in v0.0.2

func (e *MultiParenExpr) ToFuncHeaderParams() (FuncParams, *NodeError)

ToFuncHeaderParams parses the positional list as a *function header* signature (a `meti` header or a `<…>` func-header value): a bare positional entry is a *type*, not a param name, so `(int)` yields the unnamed typed param `(_ int)` (and `(mod.T)` likewise). Entries already written as `name type` (*TypedIdentExpr) are kept as-is. Otherwise it behaves like ToFuncParams.

func (*MultiParenExpr) ToFuncParams

func (e *MultiParenExpr) ToFuncParams() (params FuncParams, err *NodeError)

func (*MultiParenExpr) ToMultiParenExpr

func (e *MultiParenExpr) ToMultiParenExpr() *MultiParenExpr

func (*MultiParenExpr) WriteCode

func (e *MultiParenExpr) WriteCode(ctx *CodeWriteContext)

WriteCode renders the canonical `(, positional; named )` form inline, mirroring String. It is intentionally inline: the previous multiline path was broken — it duplicated the positional items and wrote them again in place of the named items (using PositionalElements for both loops), dropping the named side.

type NamedArgBuilder added in v0.0.2

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

func ENamedArg added in v0.0.2

func ENamedArg() *NamedArgBuilder

func (*NamedArgBuilder) Build added in v0.0.2

func (b *NamedArgBuilder) Build() *NamedArgExpr

func (*NamedArgBuilder) Expr added in v0.0.2

func (b *NamedArgBuilder) Expr(v Expr) *NamedArgBuilder

func (*NamedArgBuilder) Ident added in v0.0.2

func (*NamedArgBuilder) Literal added in v0.0.2

func (b *NamedArgBuilder) Literal(v *StrLit) *NamedArgBuilder

func (*NamedArgBuilder) Var added in v0.0.2

func (b *NamedArgBuilder) Var() *NamedArgBuilder

type NamedArgExpr

type NamedArgExpr struct {
	Lit   *StrLit
	Ident *IdentExpr
	Exp   Expr
	Var   bool
}

func (*NamedArgExpr) Expr

func (e *NamedArgExpr) Expr() Expr

func (*NamedArgExpr) Name

func (e *NamedArgExpr) Name() string

func (*NamedArgExpr) String

func (e *NamedArgExpr) String() string

func (*NamedArgExpr) WriteCode

func (e *NamedArgExpr) WriteCode(ctx *CodeWriteContext)

type NamedArgVarLit

type NamedArgVarLit struct {
	TokenPos source.Pos
	Value    Expr
}

NamedArgVarLit represents an variadic of named argument.

func (*NamedArgVarLit) End

func (e *NamedArgVarLit) End() source.Pos

func (*NamedArgVarLit) ExprNode

func (e *NamedArgVarLit) ExprNode()

func (*NamedArgVarLit) Pos

func (e *NamedArgVarLit) Pos() source.Pos

func (*NamedArgVarLit) String

func (e *NamedArgVarLit) String() string

func (*NamedArgVarLit) WriteCode

func (e *NamedArgVarLit) WriteCode(ctx *CodeWriteContext)

type NamedArgsKeywordExpr

type NamedArgsKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func NamedArgsKW

func NamedArgsKW(pos source.Pos) *NamedArgsKeywordExpr

func (*NamedArgsKeywordExpr) End

func (c *NamedArgsKeywordExpr) End() source.Pos

func (*NamedArgsKeywordExpr) ExprNode

func (c *NamedArgsKeywordExpr) ExprNode()

func (*NamedArgsKeywordExpr) Pos

func (c *NamedArgsKeywordExpr) Pos() source.Pos

func (*NamedArgsKeywordExpr) String

func (c *NamedArgsKeywordExpr) String() string

func (*NamedArgsKeywordExpr) WriteCode

func (c *NamedArgsKeywordExpr) WriteCode(ctx *CodeWriteContext)

type NamedArgsList

type NamedArgsList struct {
	Var    *IdentExpr
	Names  []*TypedIdentExpr
	Values []Expr
}

NamedArgsList represents a list of identifier with value pairs.

func NamedArgs

func NamedArgs(vari *IdentExpr, names []*TypedIdentExpr, values []Expr) NamedArgsList

func (*NamedArgsList) Add

func (n *NamedArgsList) Add(name *TypedIdentExpr, value Expr) *NamedArgsList

func (*NamedArgsList) End

func (n *NamedArgsList) End() source.Pos

End returns the position of first character immediately after the node.

func (*NamedArgsList) IsZero added in v0.0.2

func (n *NamedArgsList) IsZero() bool

func (*NamedArgsList) NumFields

func (n *NamedArgsList) NumFields() int

NumFields returns the number of fields.

func (*NamedArgsList) Pos

func (n *NamedArgsList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NamedArgsList) String

func (n *NamedArgsList) String() string

type NamedParamSpec

type NamedParamSpec struct {
	Ident *TypedIdentExpr
	Value Expr
	Var   bool
	// AbsentDefault marks a `global` default written with `!?=` (apply only when
	// the name is absent) instead of `=` (apply when nil or absent).
	AbsentDefault bool
}

A NamedParamSpec node represents a named parameter declaration

func (*NamedParamSpec) End

func (s *NamedParamSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*NamedParamSpec) Pos

func (s *NamedParamSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*NamedParamSpec) String

func (s *NamedParamSpec) String() string

func (*NamedParamSpec) WriteCode

func (s *NamedParamSpec) WriteCode(ctx *CodeWriteContext)

type NilLit

type NilLit struct {
	TokenPos source.Pos
}

NilLit represents an nil literal.

func LNil added in v0.0.2

func LNil(pos source.Pos) *NilLit

func (*NilLit) End

func (e *NilLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*NilLit) ExprNode

func (e *NilLit) ExprNode()

func (*NilLit) Pos

func (e *NilLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NilLit) String

func (e *NilLit) String() string

func (*NilLit) WriteCode

func (e *NilLit) WriteCode(ctx *CodeWriteContext)

type Node

type Node interface {
	ast.Node
	Coder
}

type NodeError

type NodeError struct {
	Node Node
	Err  string
}

func NewExpectedError

func NewExpectedError(got Node, expected ...Node) *NodeError

func NewUnExpectedError

func NewUnExpectedError(got Node) *NodeError

func (*NodeError) Error

func (e *NodeError) Error() string

func (*NodeError) Pos

func (e *NodeError) Pos() source.Pos

type NullishCallExpr added in v0.0.2

type NullishCallExpr struct {
	Func Expr
	CallArgs
}

NullishCallExpr represents an optional (nullish) call `x?.(args)`: x is evaluated once and called only when it is not nil; otherwise the whole expression evaluates to nil. It is the call counterpart of the `?.` nullish selector and is shorthand for `x != nil ? x(args) : nil`.

func (*NullishCallExpr) CallPos added in v0.0.2

func (e *NullishCallExpr) CallPos() source.Pos

CallPos returns the position of the first valid call pos.

func (*NullishCallExpr) End added in v0.0.2

func (e *NullishCallExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*NullishCallExpr) ExprNode added in v0.0.2

func (e *NullishCallExpr) ExprNode()

func (*NullishCallExpr) GetCallArgs added in v0.0.2

func (e *NullishCallExpr) GetCallArgs() *CallArgs

func (*NullishCallExpr) Pos added in v0.0.2

func (e *NullishCallExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NullishCallExpr) String added in v0.0.2

func (e *NullishCallExpr) String() string

func (*NullishCallExpr) WriteCode added in v0.0.2

func (e *NullishCallExpr) WriteCode(ctx *CodeWriteContext)

type NullishSelectorExpr

type NullishSelectorExpr struct {
	Expr Expr
	Sel  Expr
}

NullishSelectorExpr represents a selector expression.

func ENullish

func ENullish(
	sel,
	expr Expr,
) *NullishSelectorExpr

func (*NullishSelectorExpr) End

func (e *NullishSelectorExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*NullishSelectorExpr) ExprNode

func (e *NullishSelectorExpr) ExprNode()

func (*NullishSelectorExpr) GetX added in v0.0.2

func (e *NullishSelectorExpr) GetX() Expr

func (*NullishSelectorExpr) GetY added in v0.0.2

func (e *NullishSelectorExpr) GetY() Expr

func (*NullishSelectorExpr) Pos

func (e *NullishSelectorExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NullishSelectorExpr) String

func (e *NullishSelectorExpr) String() string

func (*NullishSelectorExpr) WriteCode

func (e *NullishSelectorExpr) WriteCode(ctx *CodeWriteContext)

type OrExpr added in v0.0.2

type OrExpr struct {
	Expr     Expr
	Fallback Expr
	OrPos    source.Pos
}

OrExpr represents an error-fallback expression: `expr or fallback`. If evaluating Expr throws an error, Fallback is evaluated instead, with the caught error bound to the local `$err`. The whole expression yields the value of Expr on success, or the value of Fallback when Expr throws.

func (*OrExpr) End added in v0.0.2

func (e *OrExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*OrExpr) ExprNode added in v0.0.2

func (e *OrExpr) ExprNode()

func (*OrExpr) Pos added in v0.0.2

func (e *OrExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*OrExpr) String added in v0.0.2

func (e *OrExpr) String() string

func (*OrExpr) WriteCode added in v0.0.2

func (e *OrExpr) WriteCode(ctx *CodeWriteContext)

type ParamSpec

type ParamSpec struct {
	Ident *TypedIdentExpr
	Var   bool
}

A ParamSpec node represents a parameter declaration

func (*ParamSpec) End

func (s *ParamSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*ParamSpec) Pos

func (s *ParamSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*ParamSpec) String

func (s *ParamSpec) String() string

func (*ParamSpec) WriteCode

func (s *ParamSpec) WriteCode(ctx *CodeWriteContext)

type ParenExpr

type ParenExpr struct {
	Expr   Expr
	LParen Token
	RParen Token
}

ParenExpr represents a parenthesis wrapped expression.

func EParen

func EParen(x Expr, lparen, rparen source.Pos) *ParenExpr

func (*ParenExpr) End

func (e *ParenExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ParenExpr) ExprNode

func (e *ParenExpr) ExprNode()

func (*ParenExpr) Items

func (e *ParenExpr) Items() Exprs

func (*ParenExpr) Pos

func (e *ParenExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ParenExpr) String

func (e *ParenExpr) String() string

func (*ParenExpr) ToMultiParenExpr

func (e *ParenExpr) ToMultiParenExpr() *MultiParenExpr

func (*ParenExpr) WriteCode

func (e *ParenExpr) WriteCode(ctx *CodeWriteContext)

type PropExpr added in v0.0.2

type PropExpr struct {
	PropToken TokenLit
	LBrace    source.Pos
	RBrace    source.Pos
	NameExpr  Expr
	Methods   []*FuncMethod
	Doc       *ast.CommentGroup // doc comment preceding the prop; or nil
}

PropExpr represents a property expression: a named value defined by one or more accessor methods, sharing the func-with-methods body syntax but introduced by the `prop` keyword. A method with no parameters is the getter and a method with one parameter is a setter.

func (*PropExpr) End added in v0.0.2

func (e *PropExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*PropExpr) ExprNode added in v0.0.2

func (e *PropExpr) ExprNode()

func (*PropExpr) Funcs added in v0.0.2

func (e *PropExpr) Funcs() (f Exprs)

func (*PropExpr) NameIdent added in v0.0.2

func (e *PropExpr) NameIdent() *IdentExpr

func (*PropExpr) Pos added in v0.0.2

func (e *PropExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*PropExpr) String added in v0.0.2

func (e *PropExpr) String() string

func (*PropExpr) WriteCode added in v0.0.2

func (e *PropExpr) WriteCode(ctx *CodeWriteContext)

type PropStmt added in v0.0.2

type PropStmt struct {
	PropExpr
}

PropStmt represents a property declaration statement, e.g. `prop name { () { ... } (v int) { ... } }`.

func (PropStmt) StmtNode added in v0.0.2

func (s PropStmt) StmtNode()

type Ptr added in v0.0.2

type Ptr struct {
	TokenPos source.Pos
	Expr
}

func (*Ptr) String added in v0.0.2

func (e *Ptr) String() string

func (*Ptr) WriteCode added in v0.0.2

func (e *Ptr) WriteCode(ctx *CodeWriteContext)

type RawHeredocLit

type RawHeredocLit struct {
	Literal    string
	LiteralPos source.Pos
}

func RawHeredoc

func RawHeredoc(value string, pos source.Pos) *RawHeredocLit

func (*RawHeredocLit) ContentPos added in v0.0.2

func (e *RawHeredocLit) ContentPos() source.Pos

ContentPos returns the source position of the first byte of RawContent.

func (*RawHeredocLit) End

func (e *RawHeredocLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*RawHeredocLit) ExprNode

func (e *RawHeredocLit) ExprNode()

func (*RawHeredocLit) Pos

func (e *RawHeredocLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*RawHeredocLit) RawContent added in v0.0.2

func (e *RawHeredocLit) RawContent() string

RawContent returns the heredoc body with the surrounding backtick fences, the opening fence line and the closing line removed, but with interior indentation preserved. Unlike Value it keeps a 1:1 byte correspondence with the original source starting at ContentPos, so it is what gets parsed for template interpolation so positions map back to the source.

func (*RawHeredocLit) String

func (e *RawHeredocLit) String() string

func (*RawHeredocLit) StripCount added in v0.0.2

func (e *RawHeredocLit) StripCount() int

StripCount returns the common leading indentation (spaces/tabs) removed from each content line by Value. It is zero for the single-line form (no newline after the opening fence), which is not indentation-stripped.

func (*RawHeredocLit) Value

func (e *RawHeredocLit) Value() string

func (*RawHeredocLit) WriteCode

func (e *RawHeredocLit) WriteCode(ctx *CodeWriteContext)

type RawStrLit added in v0.0.2

type RawStrLit struct {
	Literal    string
	LiteralPos source.Pos
	Quoted     bool
}

func RawStr added in v0.0.2

func RawStr(value string, pos source.Pos) *RawStrLit

func (*RawStrLit) End added in v0.0.2

func (e *RawStrLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*RawStrLit) ExprNode added in v0.0.2

func (e *RawStrLit) ExprNode()

func (*RawStrLit) Pos added in v0.0.2

func (e *RawStrLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*RawStrLit) QuotedValue added in v0.0.2

func (e *RawStrLit) QuotedValue() string

func (*RawStrLit) String added in v0.0.2

func (e *RawStrLit) String() string

func (*RawStrLit) Value added in v0.0.2

func (e *RawStrLit) Value() string

func (*RawStrLit) WriteCode added in v0.0.2

func (e *RawStrLit) WriteCode(ctx *CodeWriteContext)

type RegexLit added in v0.0.2

type RegexLit struct {
	ValuePos source.Pos
	Literal  string
}

RegexLit represents a `/regex/` (or `/regex/p` POSIX) literal. Literal holds the raw source including the delimiters and optional flag.

func (*RegexLit) End added in v0.0.2

func (e *RegexLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*RegexLit) ExprNode added in v0.0.2

func (e *RegexLit) ExprNode()

func (*RegexLit) Pattern added in v0.0.2

func (e *RegexLit) Pattern() string

Pattern returns the regex source between the delimiters, with `\/` unescaped.

func (*RegexLit) Pos added in v0.0.2

func (e *RegexLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*RegexLit) Posix added in v0.0.2

func (e *RegexLit) Posix() bool

Posix reports whether the literal carries the trailing `p` POSIX flag.

func (*RegexLit) String added in v0.0.2

func (e *RegexLit) String() string

func (*RegexLit) WriteCode added in v0.0.2

func (e *RegexLit) WriteCode(ctx *CodeWriteContext)

type Return

type Return struct {
	ReturnPos source.Pos
	Result    Expr
	Assign    bool
}

Return represents an return expression.

func (*Return) End

func (s *Return) End() source.Pos

End returns the position of first character immediately after the node.

func (*Return) Pos

func (s *Return) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*Return) String

func (s *Return) String() string

func (*Return) WriteCode

func (s *Return) WriteCode(ctx *CodeWriteContext)

type ReturnExpr

type ReturnExpr struct {
	Return
}

ReturnExpr represents an return expression.

func EReturnExpr

func EReturnExpr(pos source.Pos, result Expr) *ReturnExpr

func (*ReturnExpr) ExprNode

func (s *ReturnExpr) ExprNode()

type ReturnStmt

type ReturnStmt struct {
	Return
}

ReturnStmt represents a return statement.

func SReturn

func SReturn(pos source.Pos, result Expr) *ReturnStmt

func SReturnAssign added in v0.0.2

func SReturnAssign(pos source.Pos, result Expr) *ReturnStmt

func (*ReturnStmt) StmtNode

func (s *ReturnStmt) StmtNode()

func (*ReturnStmt) WriteCode

func (s *ReturnStmt) WriteCode(ctx *CodeWriteContext)

type SelectorExpr

type SelectorExpr struct {
	X   Expr
	Sel Expr
}

SelectorExpr represents a selector expression.

func ESelector

func ESelector(x, sel Expr) *SelectorExpr

func (*SelectorExpr) End

func (e *SelectorExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*SelectorExpr) ExprNode

func (e *SelectorExpr) ExprNode()

func (*SelectorExpr) GetX added in v0.0.2

func (e *SelectorExpr) GetX() Expr

func (*SelectorExpr) GetY added in v0.0.2

func (e *SelectorExpr) GetY() Expr

func (*SelectorExpr) Pos

func (e *SelectorExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*SelectorExpr) String

func (e *SelectorExpr) String() string

func (*SelectorExpr) WriteCode

func (e *SelectorExpr) WriteCode(ctx *CodeWriteContext)

type SliceExpr

type SliceExpr struct {
	Expr   Expr
	LBrack source.Pos
	Low    Expr
	High   Expr
	RBrack source.Pos
}

SliceExpr represents a slice expression.

func ESlice

func ESlice(
	x, low, high Expr,
	lbrack, rbrack source.Pos,
) *SliceExpr

func (*SliceExpr) End

func (e *SliceExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*SliceExpr) ExprNode

func (e *SliceExpr) ExprNode()

func (*SliceExpr) Pos

func (e *SliceExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*SliceExpr) String

func (e *SliceExpr) String() string

func (*SliceExpr) WriteCode

func (e *SliceExpr) WriteCode(ctx *CodeWriteContext)

type Spec

type Spec interface {
	ast.Node
	Coder
	// contains filtered or unexported methods
}

Spec node represents a single (non-parenthesized) variable declaration. The Spec type stands for any of *ParamSpec or *ValueSpec.

func NewNamedParamSpec

func NewNamedParamSpec(ident *TypedIdentExpr, value Expr) Spec

func NewNamedParamSpecVar added in v0.0.2

func NewNamedParamSpecVar(ident *TypedIdentExpr) Spec

func NewParamSpec

func NewParamSpec(variadic bool, ident *TypedIdentExpr) Spec

func NewValueSpec

func NewValueSpec(idents []*IdentExpr, values []Expr) Spec

type StdErrLit

type StdErrLit struct {
	TokenPos source.Pos
}

StdErrLit represents an STDERR literal.

func (*StdErrLit) End

func (e *StdErrLit) End() source.Pos

End StdErrLit the position of first character immediately after the node.

func (*StdErrLit) ExprNode

func (e *StdErrLit) ExprNode()

func (*StdErrLit) Pos

func (e *StdErrLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdErrLit) String

func (e *StdErrLit) String() string

func (*StdErrLit) WriteCode

func (e *StdErrLit) WriteCode(ctx *CodeWriteContext)

type StdInLit

type StdInLit struct {
	TokenPos source.Pos
}

StdInLit represents an STDIN literal.

func (*StdInLit) End

func (e *StdInLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StdInLit) ExprNode

func (e *StdInLit) ExprNode()

func (*StdInLit) Pos

func (e *StdInLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdInLit) String

func (e *StdInLit) String() string

func (*StdInLit) WriteCode

func (e *StdInLit) WriteCode(ctx *CodeWriteContext)

type StdOutLit

type StdOutLit struct {
	TokenPos source.Pos
}

StdOutLit represents an STDOUT literal.

func (*StdOutLit) End

func (e *StdOutLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StdOutLit) ExprNode

func (e *StdOutLit) ExprNode()

func (*StdOutLit) Pos

func (e *StdOutLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdOutLit) String

func (e *StdOutLit) String() string

func (*StdOutLit) WriteCode

func (e *StdOutLit) WriteCode(ctx *CodeWriteContext)

type Stmt

type Stmt interface {
	Node
	StmtNode()
}

Stmt represents a statement in the AST.

type Stmts

type Stmts []Stmt

func (*Stmts) Append

func (s *Stmts) Append(n ...Stmt)

func (Stmts) Each

func (s Stmts) Each(f func(i int, sep bool, s Stmt))

func (Stmts) Filter

func (s Stmts) Filter(f func(i int, s Stmt) bool) (l Stmts)

func (Stmts) Map

func (s Stmts) Map(f func(i int, s Stmt) Stmt) (l Stmts)

func (*Stmts) Prepend

func (s *Stmts) Prepend(n ...Stmt)

func (Stmts) String

func (s Stmts) String() string

func (Stmts) WriteCode

func (s Stmts) WriteCode(ctx *CodeWriteContext)

type StmtsExpr

type StmtsExpr struct {
	Stmts Stmts
}

func (*StmtsExpr) End

func (s *StmtsExpr) End() source.Pos

func (*StmtsExpr) ExprNode

func (s *StmtsExpr) ExprNode()

func (*StmtsExpr) Pos

func (s *StmtsExpr) Pos() source.Pos

func (*StmtsExpr) String

func (s *StmtsExpr) String() string

func (*StmtsExpr) WriteCode

func (s *StmtsExpr) WriteCode(ctx *CodeWriteContext)

type StrLit added in v0.0.2

type StrLit struct {
	ValuePos source.Pos
	Literal  string
}

StrLit represents a string literal.

func Str added in v0.0.2

func Str(value string, pos source.Pos) *StrLit

func (*StrLit) CanIdent added in v0.0.2

func (e *StrLit) CanIdent() bool

func (*StrLit) End added in v0.0.2

func (e *StrLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StrLit) ExprNode added in v0.0.2

func (e *StrLit) ExprNode()

func (*StrLit) Pos added in v0.0.2

func (e *StrLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StrLit) String added in v0.0.2

func (e *StrLit) String() string

func (*StrLit) Value added in v0.0.2

func (e *StrLit) Value() string

func (*StrLit) WriteCode added in v0.0.2

func (e *StrLit) WriteCode(ctx *CodeWriteContext)

type SymbolLit added in v0.0.2

type SymbolLit struct {
	Lit TokenLit
}

func LSymbol added in v0.0.2

func LSymbol(pos source.Pos, value string, paren bool) *SymbolLit

func (*SymbolLit) End added in v0.0.2

func (s *SymbolLit) End() source.Pos

func (*SymbolLit) ExprNode added in v0.0.2

func (s *SymbolLit) ExprNode()

func (*SymbolLit) Pos added in v0.0.2

func (s *SymbolLit) Pos() source.Pos

func (*SymbolLit) String added in v0.0.2

func (s *SymbolLit) String() string

func (*SymbolLit) Value added in v0.0.2

func (s *SymbolLit) Value() string

func (*SymbolLit) WriteCode added in v0.0.2

func (s *SymbolLit) WriteCode(ctx *CodeWriteContext)

type TemplateLit

type TemplateLit struct {
	TokenPos source.Pos
	Value    Expr
}

TemplateLit represents a template string literal prefixed with `#`, such as `#"text"` or `#'symbol'`. It is parsed in ParseOperand when a token.Template is followed by a string, raw string, heredoc, or symbol token. The Value field holds the string/symbol expression that follows the `#` token.

func (*TemplateLit) Build added in v0.0.2

func (e *TemplateLit) Build(sourceStmts Stmts) (expr Expr, err error)

func (*TemplateLit) End

func (e *TemplateLit) End() source.Pos

func (*TemplateLit) ExprNode

func (e *TemplateLit) ExprNode()

func (*TemplateLit) Pos

func (e *TemplateLit) Pos() source.Pos

func (*TemplateLit) String

func (e *TemplateLit) String() string

func (*TemplateLit) StringValue added in v0.0.2

func (e *TemplateLit) StringValue() string

func (*TemplateLit) StringValuePos added in v0.0.2

func (e *TemplateLit) StringValuePos() source.Pos

StringValuePos returns the source position to pass to parser.ParseTemplateString: the position of the byte immediately before the first content byte of StringValue (the template content begins one byte after it). For single-delimiter values that is the opening delimiter; for a heredoc it is the newline that ends the opening backtick line, since the surrounding backticks and the opening line are stripped from the content.

func (*TemplateLit) WriteCode

func (e *TemplateLit) WriteCode(ctx *CodeWriteContext)

type TestKind added in v0.0.2

type TestKind uint8

TestKind selects whether a TestStmt declares a test or a benchmark.

const (
	// TestKindTest is a `test NAME { … }` statement.
	TestKindTest TestKind = iota
	// TestKindBench is a `bench NAME { … }` statement.
	TestKindBench
)

func (TestKind) String added in v0.0.2

func (k TestKind) String() string

String returns the keyword spelling (`test` or `bench`).

type TestStmt added in v0.0.2

type TestStmt struct {
	Kind    TestKind
	KwPos   source.Pos // position of the `test`/`bench` keyword
	Name    string     // the test name (identifier spelling or string value)
	NamePos source.Pos
	Quoted  bool // NAME was written as a string literal
	Body    *BlockStmt
	Doc     *ast.CommentGroup // doc comment preceding the statement; or nil
}

TestStmt is a `test NAME { … }` or `bench NAME { … }` statement. NAME is an identifier or a string literal; the body runs with an injected `t` test context (see the `test` module). `test`/`bench` are contextual: they are only this statement when followed by a NAME and `{`, so they remain ordinary identifiers everywhere else.

func (*TestStmt) End added in v0.0.2

func (s *TestStmt) End() source.Pos

func (*TestStmt) Pos added in v0.0.2

func (s *TestStmt) Pos() source.Pos

func (*TestStmt) StmtNode added in v0.0.2

func (s *TestStmt) StmtNode()

func (*TestStmt) String added in v0.0.2

func (s *TestStmt) String() string

func (*TestStmt) WriteCode added in v0.0.2

func (s *TestStmt) WriteCode(ctx *CodeWriteContext)

type ThrowExpr

type ThrowExpr struct {
	ThrowPos source.Pos
	Expr     Expr
}

ThrowExpr represents an throw expression.

func (*ThrowExpr) End

func (s *ThrowExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ThrowExpr) ExprNode

func (s *ThrowExpr) ExprNode()

func (*ThrowExpr) Pos

func (s *ThrowExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ThrowExpr) String

func (s *ThrowExpr) String() string

func (*ThrowExpr) WriteCode

func (s *ThrowExpr) WriteCode(ctx *CodeWriteContext)

type ThrowStmt

type ThrowStmt struct {
	ThrowPos source.Pos
	Expr     Expr
}

ThrowStmt represents an throw statement.

func SThrow

func SThrow(
	throwPos source.Pos,
	expr Expr,
) *ThrowStmt

func (*ThrowStmt) End

func (s *ThrowStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ThrowStmt) Pos

func (s *ThrowStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ThrowStmt) StmtNode

func (s *ThrowStmt) StmtNode()

func (*ThrowStmt) String

func (s *ThrowStmt) String() string

func (*ThrowStmt) WriteCode

func (s *ThrowStmt) WriteCode(ctx *CodeWriteContext)

type ToMultiParenConverter

type ToMultiParenConverter interface {
	Expr
	ToMultiParenExpr() *MultiParenExpr
}

type ToRaw added in v0.0.2

type ToRaw struct {
	TokenPos source.Pos
	Expr     Expr
}

func EToRaw added in v0.0.2

func EToRaw(pos source.Pos, e Expr) *ToRaw

func (*ToRaw) End added in v0.0.2

func (r *ToRaw) End() source.Pos

func (*ToRaw) ExprNode added in v0.0.2

func (r *ToRaw) ExprNode()

func (*ToRaw) Pos added in v0.0.2

func (r *ToRaw) Pos() source.Pos

func (*ToRaw) String added in v0.0.2

func (r *ToRaw) String() string

func (*ToRaw) WriteCode added in v0.0.2

func (r *ToRaw) WriteCode(ctx *CodeWriteContext)

type Token added in v0.0.2

type Token struct {
	Pos   source.Pos
	Token token.Token
}

func (Token) Valid added in v0.0.2

func (t Token) Valid() bool

type TokenLit added in v0.0.2

type TokenLit struct {
	Pos     source.Pos
	Token   token.Token
	Literal string
}

func (TokenLit) Is added in v0.0.2

func (t TokenLit) Is(other ...token.Token) bool

func (TokenLit) Precedence added in v0.0.2

func (t TokenLit) Precedence() int

func (TokenLit) String added in v0.0.2

func (t TokenLit) String() string

func (TokenLit) Valid added in v0.0.2

func (t TokenLit) Valid() bool

type TranspileOptions

type TranspileOptions struct {
	RawStrFuncStart string
	RawStrFuncEnd   string
	WriteFunc       string
}

type TryStmt

type TryStmt struct {
	TryPos  source.Pos
	Body    *BlockStmt
	Catch   *CatchStmt   // catch branch; or nil
	Finally *FinallyStmt // finally branch; or nil
}

TryStmt represents an try statement.

func STry

func STry(
	tryPos source.Pos,
	body *BlockStmt,
	catch *CatchStmt,
	finally *FinallyStmt,
) *TryStmt

func (*TryStmt) End

func (s *TryStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*TryStmt) Pos

func (s *TryStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*TryStmt) StmtNode

func (s *TryStmt) StmtNode()

func (*TryStmt) String

func (s *TryStmt) String() string

func (*TryStmt) WriteCode

func (s *TryStmt) WriteCode(ctx *CodeWriteContext)

type TypeExpr added in v0.0.2

type TypeExpr struct {
	Expr
}

func EType added in v0.0.2

func EType(expr Expr) *TypeExpr

func (*TypeExpr) End added in v0.0.2

func (e *TypeExpr) End() source.Pos

func (*TypeExpr) ExprNode added in v0.0.2

func (e *TypeExpr) ExprNode()

func (*TypeExpr) Ident added in v0.0.2

func (e *TypeExpr) Ident() *IdentExpr

func (*TypeExpr) Pos added in v0.0.2

func (e *TypeExpr) Pos() source.Pos

type TypedIdentExpr

type TypedIdentExpr struct {
	Ident *IdentExpr
	Type  []*TypeExpr
}

func ETypedIdent

func ETypedIdent(ident *IdentExpr, typ ...*TypeExpr) *TypedIdentExpr

func FuncReturn added in v0.0.2

func FuncReturn(types ...*TypedIdentExpr) []*TypedIdentExpr

FuncReturn builds a function return-type list from typed idents.

func (*TypedIdentExpr) End

func (e *TypedIdentExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*TypedIdentExpr) ExprNode

func (e *TypedIdentExpr) ExprNode()

func (*TypedIdentExpr) Pos

func (e *TypedIdentExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*TypedIdentExpr) String

func (e *TypedIdentExpr) String() string

func (*TypedIdentExpr) WriteCode

func (e *TypedIdentExpr) WriteCode(ctx *CodeWriteContext)

type UintLit

type UintLit struct {
	Value    uint64
	ValuePos source.Pos
	Literal  string
}

UintLit represents an unsigned integer literal.

func (*UintLit) End

func (e *UintLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*UintLit) ExprNode

func (e *UintLit) ExprNode()

func (*UintLit) Pos

func (e *UintLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*UintLit) String

func (e *UintLit) String() string

func (*UintLit) WriteCode

func (e *UintLit) WriteCode(ctx *CodeWriteContext)

type UnaryExpr

type UnaryExpr struct {
	Expr     Expr
	Token    token.Token
	TokenPos source.Pos
}

UnaryExpr represents an unary operator expression.

func EUnary

func EUnary(x Expr, op token.Token, pos source.Pos) *UnaryExpr

func (*UnaryExpr) End

func (e *UnaryExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*UnaryExpr) ExprNode

func (e *UnaryExpr) ExprNode()

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

func (*UnaryExpr) WriteCode

func (e *UnaryExpr) WriteCode(ctx *CodeWriteContext)

type ValueSpec

type ValueSpec struct {
	Idents []*IdentExpr // TODO: slice is reserved for tuple assignment
	Values []Expr       // initial values; or nil
	// Pattern is a destructuring left side (`const { … } = v` / `const [ … ] = v`).
	// When set, Idents is empty and Values holds the single source expression.
	Pattern Expr
	Data    any               // iota
	Doc     *ast.CommentGroup // doc comment preceding the spec (linked to ident); or nil
}

A ValueSpec node represents a variable declaration

func (*ValueSpec) End

func (s *ValueSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*ValueSpec) Pos

func (s *ValueSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*ValueSpec) String

func (s *ValueSpec) String() string

func (*ValueSpec) WriteCode

func (s *ValueSpec) WriteCode(ctx *CodeWriteContext)

type WithBind added in v0.0.2

type WithBind int

WithBind selects how a `with` statement binds its resource.

const (
	WithBindNone   WithBind = iota // with Resource { ... }
	WithBindAs                     // with Resource as IDENT { ... }
	WithBindAssign                 // with IDENT = Resource { ... }
	WithBindDefine                 // with IDENT := Resource { ... }
)

type WithExpr added in v0.0.2

type WithExpr struct {
	WithPos  source.Pos
	Resource Expr
	Ident    *IdentExpr // `as IDENT`, or nil
	ColonPos source.Pos
	Value    Expr
}

WithExpr is the expression form `with Resource [as IDENT]: Value`: it enters the resource (gad.enter), evaluates Value, exits (gad.exit) and yields Value.

func (*WithExpr) End added in v0.0.2

func (e *WithExpr) End() source.Pos

func (*WithExpr) ExprNode added in v0.0.2

func (e *WithExpr) ExprNode()

func (*WithExpr) Pos added in v0.0.2

func (e *WithExpr) Pos() source.Pos

func (*WithExpr) String added in v0.0.2

func (e *WithExpr) String() string

func (*WithExpr) WriteCode added in v0.0.2

func (e *WithExpr) WriteCode(ctx *CodeWriteContext)

type WithStmt added in v0.0.2

type WithStmt struct {
	WithPos  source.Pos
	Bind     WithBind
	Ident    *IdentExpr
	Resource Expr
	Body     *BlockStmt
}

WithStmt represents a `with` context-manager statement. The resource's enter/exit hooks (gad.enter / gad.exit) run around Body. Resource is the context value; Ident is the `as` block-local binding or the assign/define target (nil for WithBindNone).

func (*WithStmt) End added in v0.0.2

func (s *WithStmt) End() source.Pos

func (*WithStmt) Pos added in v0.0.2

func (s *WithStmt) Pos() source.Pos

func (*WithStmt) StmtNode added in v0.0.2

func (s *WithStmt) StmtNode()

func (*WithStmt) String added in v0.0.2

func (s *WithStmt) String() string

func (*WithStmt) WriteCode added in v0.0.2

func (s *WithStmt) WriteCode(ctx *CodeWriteContext)

Jump to

Keyboard shortcuts

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