Documentation
¶
Index ¶
- Constants
- func Code(n Coder, opt ...CodeOption) string
- func CodeW(w io.Writer, n Coder, opt ...CodeOption)
- func FormatFuncReturn(ret []*TypedIdentExpr) string
- func FormatTypeParams(tps []*TypedIdentExpr) string
- func IdentNames(n ast.Node) map[string]struct{}
- func IsExpr(n Node) (ok bool)
- func IsStatement(v Node) (ok bool)
- func Lit(value string, pos source.Pos) ast.Literal
- func MetaCode(meta *KeyValueArrayLit) string
- func Walk(root ast.Node, f func(ast.Node) bool)
- func WithCallArgs[T interface{ ... }](e T, do func(args *CallArgs)) T
- func WriteFuncReturn(ctx *CodeWriteContext, ret []*TypedIdentExpr)
- type ArgVarLit
- type ArgsKeywordExpr
- type ArgsList
- type ArrayComprehension
- type ArrayExpr
- type ArrayTypeExpr
- type AssignStmt
- type BadDecl
- type BadExpr
- type BadStmt
- type BinaryExpr
- type BlockExpr
- type BlockStmt
- type BoolExpr
- type BoolLit
- type BranchStmt
- type BytesLit
- type BytesLitPrefix
- type CallArgs
- func (c *CallArgs) Arg(e ...Expr) *CallArgs
- func (c *CallArgs) ArgVar(pos source.Pos, e Expr) *CallArgs
- func (c *CallArgs) End() source.Pos
- func (c *CallArgs) NamedFlag(e ...Expr) *CallArgs
- func (c *CallArgs) NamedValue(e ...Expr) *CallArgs
- func (c *CallArgs) Pos() source.Pos
- func (c *CallArgs) String() string
- func (c *CallArgs) StringArg(w io.Writer, lbrace, rbrace string)
- func (c *CallArgs) StringW(w io.Writer)
- func (c *CallArgs) ToFuncParams() (fp *FuncParams, err error)
- func (c *CallArgs) WriteCode(ctx *CodeWriteContext)
- func (c *CallArgs) WriteCodeBrace(ctx *CodeWriteContext, lbrace, rbrace string)
- type CallExpr
- type CallExprNamedArgs
- func (a *CallExprNamedArgs) Append(name *NamedArgExpr, value Expr) *CallExprNamedArgs
- func (a *CallExprNamedArgs) AppendE(name Expr, value Expr) *CallExprNamedArgs
- func (a *CallExprNamedArgs) AppendFlagE(name Expr) *CallExprNamedArgs
- func (a *CallExprNamedArgs) AppendFlags(name ...string) *CallExprNamedArgs
- func (a *CallExprNamedArgs) AppendS(name string, value Expr) *CallExprNamedArgs
- func (a *CallExprNamedArgs) Get(name NamedArgExpr) (index int, value Expr)
- func (a *CallExprNamedArgs) NamesExpr() (r []Expr)
- func (a *CallExprNamedArgs) Prepend(name *NamedArgExpr, value Expr) *CallExprNamedArgs
- func (a *CallExprNamedArgs) String() string
- func (a *CallExprNamedArgs) Valid() bool
- func (a *CallExprNamedArgs) Var() *NamedArgExpr
- func (a *CallExprNamedArgs) WriteCode(ctx *CodeWriteContext, inNewLime, hasPositional bool)
- func (a *CallExprNamedArgs) WriteCodeWithFlag(inNewLine, hasPositional bool, ctx *CodeWriteContext)
- type CallExprPositionalArgs
- type CalleeKeywordExpr
- type CatchStmt
- type CharLit
- type ClassFieldExpr
- type ClassMemberExpr
- type ClassParentExpr
- type ClosureExpr
- type CodeBeginStmt
- type CodeEndStmt
- type CodeOption
- func CodeFormat() CodeOption
- func CodeNewLineCalc(maxColumns int) CodeOption
- func CodeTranspile(v *TranspileOptions) CodeOption
- func CodeWithComments(f *source.File, groups []*ast.CommentGroup) CodeOption
- func CodeWithFlags(flag CodeWriteContextFlag) CodeOption
- func CodeWithMaxColumns(maxColumns int) CodeOption
- func CodeWithMinimalParens() CodeOption
- func CodeWithParenMarks() CodeOption
- func CodeWithPrefix(prefix string) CodeOption
- type CodeStrLit
- type CodeWriteContext
- func (ctx CodeWriteContext) Buffer(do func(ctx *CodeWriteContext)) string
- func (ctx *CodeWriteContext) Column() int
- func (ctx *CodeWriteContext) CurrentPrefix() string
- func (ctx *CodeWriteContext) DecideNewLine(flag CodeWriteContextFlag, count int, inlineSep string, closing int, ...) bool
- func (ctx *CodeWriteContext) DecideNewLineFunc(flag CodeWriteContextFlag, count, closing int, renderInline func()) bool
- func (ctx *CodeWriteContext) HasPrefix() bool
- func (ctx *CodeWriteContext) Pop()
- func (ctx *CodeWriteContext) PrevPrefix() string
- func (ctx *CodeWriteContext) Printf(format string, args ...interface{})
- func (ctx *CodeWriteContext) Push(n ast.Node)
- func (ctx *CodeWriteContext) Top() ast.Node
- func (ctx *CodeWriteContext) With(n ast.Node, cb func() error) (err error)
- func (ctx CodeWriteContext) WithoutPrefix() *CodeWriteContext
- func (ctx *CodeWriteContext) WriteExprs(sep string, expr ...Expr)
- func (ctx *CodeWriteContext) WriteGreedy(count int, itemSep, breakConnector string, do func(i int))
- func (ctx *CodeWriteContext) WriteItems(inNewLine bool, count int, do func(i int), done func(newLine bool))
- func (ctx *CodeWriteContext) WriteItemsSep(inNewLine bool, count int, inlineSep, newLineSep string, do func(i int), ...)
- func (ctx *CodeWriteContext) WriteItemsWithComments(count int, newLineSep string, endOf func(i int) source.Pos, do func(i int), ...)
- func (ctx *CodeWriteContext) WriteLeadDoc(g *ast.CommentGroup) bool
- func (ctx *CodeWriteContext) WriteLine(s string)
- func (ctx *CodeWriteContext) WritePrefix()
- func (ctx *CodeWriteContext) WritePrefixedLine()
- func (ctx *CodeWriteContext) WritePrevPrefix()
- func (ctx *CodeWriteContext) WriteSecondLine()
- func (ctx *CodeWriteContext) WriteSemi()
- func (ctx *CodeWriteContext) WriteSemiOrDoubleLine()
- func (ctx *CodeWriteContext) WriteStmts(stmt ...Stmt)
- func (ctx *CodeWriteContext) WriteTrailingDoc(g *ast.CommentGroup) bool
- type CodeWriteContextFlag
- func (b *CodeWriteContextFlag) Clear(flag CodeWriteContextFlag) *CodeWriteContextFlag
- func (b CodeWriteContextFlag) Has(flag ...CodeWriteContextFlag) bool
- func (b *CodeWriteContextFlag) Set(flag CodeWriteContextFlag) *CodeWriteContextFlag
- func (b *CodeWriteContextFlag) Toggle(flag CodeWriteContextFlag) *CodeWriteContextFlag
- type CodeWriteSkiper
- type CodeWriter
- type Coder
- type ComprehensionClause
- type ComputedExpr
- type CondExpr
- type ConfigOptions
- type ConfigStmt
- type DateTimeLit
- type DateTimeLitKind
- type DecimalLit
- type Decl
- type DeclStmt
- type DeferStmt
- type DeferVariant
- type DeleteStmt
- type DictComprehension
- type DictElementFuncExprs
- type DictElementLit
- func (e *DictElementLit) BuildKeyExpr() Expr
- func (e *DictElementLit) End() source.Pos
- func (e *DictElementLit) ExprNode()
- func (e *DictElementLit) Func() (f *FuncDefLit)
- func (e *DictElementLit) IsFunc() (ok bool)
- func (e *DictElementLit) Pos() source.Pos
- func (e *DictElementLit) String() string
- func (e *DictElementLit) WriteCode(ctx *CodeWriteContext)
- type DictExpr
- type DotFileLit
- type DotFileNameLit
- type DurationLit
- type EmbedExpr
- func (e *EmbedExpr) ConfigFile() string
- func (e *EmbedExpr) End() source.Pos
- func (e *EmbedExpr) Excludes() []string
- func (e *EmbedExpr) ExcludesRe() []string
- func (e *EmbedExpr) ExprNode()
- func (e *EmbedExpr) Includes() []string
- func (e *EmbedExpr) IncludesRe() []string
- func (e *EmbedExpr) Path() (s string)
- func (e *EmbedExpr) Pos() source.Pos
- func (e *EmbedExpr) Sources() []string
- func (e *EmbedExpr) String() string
- func (e *EmbedExpr) Tree() bool
- func (e *EmbedExpr) WriteCode(ctx *CodeWriteContext)
- type EmptyStmt
- type EnumExpr
- type EnumFieldExpr
- type EnumStmt
- type EnvLit
- type ExportStmt
- type Expr
- type ExprSelector
- type ExprStmt
- type Exprs
- type FilesLit
- type FinallyStmt
- type FlagLit
- type FloatLit
- type ForInStmt
- type ForStmt
- type FuncDefLit
- type FuncExpr
- type FuncHeader
- type FuncHeaderExpr
- type FuncMethod
- type FuncParams
- type FuncStmt
- type FuncType
- type FuncWithMethodsExpr
- func (e *FuncWithMethodsExpr) End() source.Pos
- func (e *FuncWithMethodsExpr) ExprNode()
- func (e *FuncWithMethodsExpr) Funcs() (f Exprs)
- func (e *FuncWithMethodsExpr) NameIdent() *IdentExpr
- func (e *FuncWithMethodsExpr) Pos() source.Pos
- func (e *FuncWithMethodsExpr) String() string
- func (e *FuncWithMethodsExpr) WriteCode(ctx *CodeWriteContext)
- type FuncWithMethodsStmt
- type GenDecl
- type GlobalsLit
- type HeredocLit
- func (e *HeredocLit) ContentPos() source.Pos
- func (e *HeredocLit) End() source.Pos
- func (e *HeredocLit) ExprNode()
- func (e *HeredocLit) Pos() source.Pos
- func (e *HeredocLit) RawContent() string
- func (e *HeredocLit) String() string
- func (e *HeredocLit) StripCount() int
- func (e *HeredocLit) Value() string
- func (e *HeredocLit) WriteCode(ctx *CodeWriteContext)
- type IdentExpr
- type IdentList
- type IfStmt
- type ImportExpr
- type IncDecStmt
- type IncludeStmt
- type IndexExpr
- type IntLit
- type InterfaceContextFuncExpr
- type InterfaceExpr
- type InterfaceMemberExpr
- type InterfaceMemberKind
- type InterfaceMethodExpr
- type InterfaceStmt
- type InterpolatedStringLit
- func (e *InterpolatedStringLit) Build(sourceStmts Stmts) (expr Expr, err error)
- func (e *InterpolatedStringLit) End() source.Pos
- func (e *InterpolatedStringLit) ExprNode()
- func (e *InterpolatedStringLit) Pos() source.Pos
- func (e *InterpolatedStringLit) String() string
- func (e *InterpolatedStringLit) StringValue() string
- func (e *InterpolatedStringLit) StringValuePos() source.Pos
- func (e *InterpolatedStringLit) WriteCode(ctx *CodeWriteContext)
- type IsMainLit
- type KeyValueArrayLit
- type KeyValueLit
- type KeyValuePairLit
- func (e *KeyValuePairLit) End() source.Pos
- func (e *KeyValuePairLit) ExprNode()
- func (e *KeyValuePairLit) Func() (f *FuncDefLit)
- func (e *KeyValuePairLit) IsFunc() (ok bool)
- func (e *KeyValuePairLit) Pos() source.Pos
- func (e *KeyValuePairLit) String() string
- func (e *KeyValuePairLit) WriteCode(ctx *CodeWriteContext)
- type MatchArm
- type MatchExpr
- type MetaTypeExpr
- type MethodExpr
- type MethodInterfaceExpr
- type MethodInterfaceStmt
- type MixedTextExpr
- type MixedTextStmt
- func (s *MixedTextStmt) End() source.Pos
- func (s *MixedTextStmt) ExprNode()
- func (s *MixedTextStmt) Pos() source.Pos
- func (s *MixedTextStmt) StmtNode()
- func (s *MixedTextStmt) String() string
- func (s *MixedTextStmt) TrimLinePrefix(prefix string)
- func (s *MixedTextStmt) ValidLit() ast.Literal
- func (s *MixedTextStmt) Value() string
- func (s *MixedTextStmt) WriteCode(ctx *CodeWriteContext)
- type MixedTextStmtFlag
- type MixedValueStmt
- type ModLit
- type ModuleLit
- type MultiParenExpr
- func (e *MultiParenExpr) End() source.Pos
- func (e *MultiParenExpr) ExprNode()
- func (e *MultiParenExpr) Pos() source.Pos
- func (e *MultiParenExpr) String() string
- func (e *MultiParenExpr) ToCallArgs(strict bool) (args *CallArgs, err *NodeError)
- func (e *MultiParenExpr) ToFuncHeaderParams() (FuncParams, *NodeError)
- func (e *MultiParenExpr) ToFuncParams() (params FuncParams, err *NodeError)
- func (e *MultiParenExpr) ToMultiParenExpr() *MultiParenExpr
- func (e *MultiParenExpr) WriteCode(ctx *CodeWriteContext)
- type NamedArgBuilder
- type NamedArgExpr
- type NamedArgVarLit
- type NamedArgsKeywordExpr
- type NamedArgsList
- type NamedParamSpec
- type NilLit
- type Node
- type NodeError
- type NullishCallExpr
- func (e *NullishCallExpr) CallPos() source.Pos
- func (e *NullishCallExpr) End() source.Pos
- func (e *NullishCallExpr) ExprNode()
- func (e *NullishCallExpr) GetCallArgs() *CallArgs
- func (e *NullishCallExpr) Pos() source.Pos
- func (e *NullishCallExpr) String() string
- func (e *NullishCallExpr) WriteCode(ctx *CodeWriteContext)
- type NullishSelectorExpr
- func (e *NullishSelectorExpr) End() source.Pos
- func (e *NullishSelectorExpr) ExprNode()
- func (e *NullishSelectorExpr) GetX() Expr
- func (e *NullishSelectorExpr) GetY() Expr
- func (e *NullishSelectorExpr) Pos() source.Pos
- func (e *NullishSelectorExpr) String() string
- func (e *NullishSelectorExpr) WriteCode(ctx *CodeWriteContext)
- type OrExpr
- type ParamSpec
- type ParenExpr
- type PropExpr
- type PropStmt
- type Ptr
- type PtrTypeExpr
- type RawHeredocLit
- func (e *RawHeredocLit) ContentPos() source.Pos
- func (e *RawHeredocLit) End() source.Pos
- func (e *RawHeredocLit) ExprNode()
- func (e *RawHeredocLit) Pos() source.Pos
- func (e *RawHeredocLit) RawContent() string
- func (e *RawHeredocLit) String() string
- func (e *RawHeredocLit) StripCount() int
- func (e *RawHeredocLit) Value() string
- func (e *RawHeredocLit) WriteCode(ctx *CodeWriteContext)
- type RawStrLit
- type RegexLit
- type Return
- type ReturnExpr
- type ReturnStmt
- type SelectorExpr
- type SliceExpr
- type Spec
- type StdErrLit
- type StdInLit
- type StdOutLit
- type Stmt
- type Stmts
- func (s *Stmts) Append(n ...Stmt)
- func (s Stmts) Each(f func(i int, sep bool, s Stmt))
- func (s Stmts) Filter(f func(i int, s Stmt) bool) (l Stmts)
- func (s Stmts) Map(f func(i int, s Stmt) Stmt) (l Stmts)
- func (s *Stmts) Prepend(n ...Stmt)
- func (s Stmts) String() string
- func (s Stmts) WriteCode(ctx *CodeWriteContext)
- type StmtsExpr
- type StrLit
- type SymbolLit
- type TestKind
- type TestStmt
- type ThrowExpr
- type ThrowStmt
- type ToMultiParenConverter
- type ToRaw
- type Token
- type TokenLit
- type TranspileOptions
- type TryStmt
- type TypeArgsExpr
- type TypeDeclStmt
- type TypeExpr
- type TypeLitExpr
- type TypeUnionExpr
- type TypedArrayTypeStmt
- type TypedIdentExpr
- type UintLit
- type UnaryExpr
- type ValueSpec
- type WithBind
- type WithExpr
- type WithStmt
Constants ¶
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 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 FormatTypeParams ¶
func FormatTypeParams(tps []*TypedIdentExpr) string
FormatTypeParams renders a type-parameter list including its brackets (`[T indexable, K int | uint]`), or "" when the list is empty.
func IdentNames ¶
IdentNames returns the set of identifier names appearing anywhere in n. It is an over-approximation of the free variables of an expression (it also includes bound names, selector field names, etc.), which is what callers that must not miss a reference — e.g. the declaration reorderer's scope check — rely on.
func IsStatement ¶
IsStatement returns true if given value is implements interface{ StmtNode() }.
func MetaCode ¶
func MetaCode(meta *KeyValueArrayLit) string
MetaCode renders a `[k=v, …]` metadata block as source (`[a=1, b]`), or "" when meta is nil/empty — for documentation and tooling.
func Walk ¶
Walk traverses the AST rooted at root in depth-first pre-order, calling f for every ast.Node it reaches (starting with root). When f returns false the children of that node are skipped; returning true descends into them.
Traversal is reflection-based, so it covers every node type — including custom implementations (gadx) — without a per-type switch: it follows exported fields that are ast.Nodes and descends into slices, arrays, maps, pointers, interfaces and plain structs that may contain them. Unexported fields are not followed (reflection cannot read them), and nil interfaces/pointers are handled.
func WithCallArgs ¶ added in v0.0.2
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 ¶
ArgVarLit represents an variadic of argument.
func (*ArgVarLit) WriteCode ¶
func (e *ArgVarLit) WriteCode(ctx *CodeWriteContext)
type ArgsKeywordExpr ¶
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 (*ArgsList) PrependValue ¶
func (n *ArgsList) PrependValue(v ...*TypedIdentExpr)
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 ¶
ArrayExpr represents an array literal.
func (*ArrayExpr) WriteCode ¶
func (e *ArrayExpr) WriteCode(ctx *CodeWriteContext)
type ArrayTypeExpr ¶
type ArrayTypeExpr struct {
LBrack source.Pos
// Depth is how many `[]` were written: 1 for `[]int`, 3 for `[][][]int`.
Depth int
// Types are the types the element may be: one, or several when the envelope
// was used.
Types []*TypeExpr
// Enveloped says the element types were written inside `<…>`. `[]int` is the
// SHORT FORM of `[]<int>` — one type needs no envelope — and both print
// short.
Enveloped bool
RAngle source.Pos
}
ArrayTypeExpr is a slice written where a type goes: `[]int`, `[][]str` — the `[]` repeated is the nesting depth — and `[]<int|str>`, where the angle brackets envelope several types the element may be. `[]int` is the short form of `[]<int>`: one type needs no envelope.
Inside the envelope the element types are read by the same parser as a parameter's, so a slice of function headers is `[]<<(x int) <ret any>>`.
func (*ArrayTypeExpr) End ¶
func (e *ArrayTypeExpr) End() source.Pos
func (*ArrayTypeExpr) ExprNode ¶
func (e *ArrayTypeExpr) ExprNode()
func (*ArrayTypeExpr) Pos ¶
func (e *ArrayTypeExpr) Pos() source.Pos
func (*ArrayTypeExpr) String ¶
func (e *ArrayTypeExpr) String() string
func (*ArrayTypeExpr) WriteCode ¶
func (e *ArrayTypeExpr) WriteCode(ctx *CodeWriteContext)
type AssignStmt ¶
AssignStmt represents an assignment statement.
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 ¶
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
func (*BadDecl) WriteCode ¶
func (d *BadDecl) WriteCode(ctx *CodeWriteContext)
type BadExpr ¶
BadExpr represents a bad expression.
func (*BadExpr) WriteCode ¶
func (e *BadExpr) WriteCode(ctx *CodeWriteContext)
type BadStmt ¶
BadStmt represents a bad statement.
func (*BadStmt) WriteCode ¶
func (s *BadStmt) WriteCode(ctx *CodeWriteContext)
type BinaryExpr ¶
BinaryExpr represents a binary operator expression.
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 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 (*BlockStmt) WriteCode ¶
func (s *BlockStmt) WriteCode(ctx *CodeWriteContext)
type BoolLit ¶
BoolLit represents a boolean literal.
func (*BoolLit) WriteCode ¶
func (e *BoolLit) WriteCode(ctx *CodeWriteContext)
type BranchStmt ¶
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
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
End returns the position immediately after the underlying string literal.
func (*BytesLit) StrValue ¶ added in v0.0.2
StrValue returns the decoded string content of the underlying string literal.
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 (*CallArgs) NamedValue ¶ added in v0.0.2
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 ¶
CallExpr represents a function call expression.
func ECallProxy ¶
func (*CallExpr) GetCallArgs ¶ added in v0.0.2
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
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 ¶
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 (*CatchStmt) WriteCode ¶
func (s *CatchStmt) WriteCode(ctx *CodeWriteContext)
type CharLit ¶
CharLit represents a character literal.
func (*CharLit) WriteCode ¶
func (e *CharLit) 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
// Meta is the field's `[k=v, …]` metadata (or nil); read as `Class.field.@meta`.
Meta *KeyValueArrayLit
// Group marks a field written as a group — `{ … }`, `? { … }` —: named
// `$N` (N its count in the body), typed by the anonymous class of the
// block; it is written back as the block.
Group bool
}
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
// Meta is the member's `[k=v, …]` metadata (or nil).
Meta *KeyValueArrayLit
}
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 ClosureExpr ¶
type ClosureExpr struct {
ast.NodeData
TypeParams []*TypedIdentExpr
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 (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. It does NOT set the per-construct force bits (…Format): those are opt-in and, when set, force that construct onto separate lines regardless of the column 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 CodeWithMaxColumns ¶
func CodeWithMaxColumns(maxColumns int) CodeOption
CodeWithMaxColumns sets the line-width budget for NEW_LINE_CALC wrapping (<= 0 keeps DefaultMaxColumns).
func CodeWithMinimalParens ¶
func CodeWithMinimalParens() CodeOption
CodeWithMinimalParens writes only the parentheses of the source (see CodeWriteContext.MinimalParens).
func CodeWithParenMarks ¶
func CodeWithParenMarks() CodeOption
CodeWithParenMarks writes the tree's own parentheses marked (see CodeWriteContext.ParenMarks), for comparing two trees.
func CodeWithPrefix ¶
func CodeWithPrefix(prefix string) CodeOption
type CodeStrLit ¶ added in v0.0.2
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
// MinimalParens writes the parentheses of the source and no others: a
// binary, a unary, a conditional do not wrap themselves (each written
// parenthesis is a ParenExpr of the parse). It is for code formatted from
// its source (`gad fmt`); a tree made by code keeps the safe, fully
// parenthesized form.
MinimalParens bool
// ParenMarks writes each parenthesis of the tree marked (`⟨(…)⟩`) beside
// those every operation is written in: not code, a form for telling
// whether two trees are the same — one with a ParenExpr where the other
// has none differs.
ParenMarks bool
// 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 (*CodeWriteContext) WriteItemsWithComments ¶
func (ctx *CodeWriteContext) WriteItemsWithComments(count int, newLineSep string, endOf func(i int) source.Pos, do func(i int), done func(newLine bool))
WriteItemsWithComments is the multi-line item writer (WriteItemsSep's newLine branch) that also emits each item's trailing same-line source comment right after it, so inline comments survive formatting instead of being relocated. endOf gives an item's end position (to match comments on the same source line); done runs before the indent is popped, exactly like WriteItemsSep, so callers reuse their own closing.
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 (b *CodeWriteContextFlag) Clear(flag CodeWriteContextFlag) *CodeWriteContextFlag
func (CodeWriteContextFlag) Has ¶ added in v0.0.2
func (b CodeWriteContextFlag) Has(flag ...CodeWriteContextFlag) bool
func (*CodeWriteContextFlag) Set ¶ added in v0.0.2
func (b *CodeWriteContextFlag) Set(flag CodeWriteContextFlag) *CodeWriteContextFlag
func (*CodeWriteContextFlag) Toggle ¶ added in v0.0.2
func (b *CodeWriteContextFlag) Toggle(flag CodeWriteContextFlag) *CodeWriteContextFlag
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
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 ¶
CondExpr represents a ternary conditional expression.
func (*CondExpr) WriteCode ¶
func (e *CondExpr) WriteCode(ctx *CodeWriteContext)
type ConfigOptions ¶
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 ¶
DecimalLit represents a floating point literal.
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 DeclStmt ¶
type DeclStmt struct {
Decl // *GenDecl with VAR token
}
A DeclStmt node represents a declaration in a statement list.
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
End returns the position of first character immediately after the node.
func (*DeferStmt) Keyword ¶ added in v0.0.2
Keyword returns the source keyword for this statement (defer / defer_ok / deferb_err / ...).
func (*DeferStmt) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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 DeleteStmt ¶
DeleteStmt is the `delete` statement: it removes one or more keys from a target object.
delete Target.field // Keys == nil: delete the single key "field" delete Target [k1, k2, …] // Keys is an array/expr: delete each key
In the selector form (Keys == nil) Target is a *SelectorExpr whose base is the object and whose selector name is the (string) key. Otherwise Target is the object and Keys evaluates to the key or an array of keys.
func (*DeleteStmt) End ¶
func (s *DeleteStmt) End() source.Pos
End returns the position of first character immediately after the node.
func (*DeleteStmt) Pos ¶
func (s *DeleteStmt) Pos() source.Pos
Pos returns the position of first character belonging to the node.
func (*DeleteStmt) StmtNode ¶
func (s *DeleteStmt) StmtNode()
func (*DeleteStmt) String ¶
func (s *DeleteStmt) String() string
func (*DeleteStmt) WriteCode ¶
func (s *DeleteStmt) WriteCode(ctx *CodeWriteContext)
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 (*DictExpr) WriteCode ¶
func (e *DictExpr) WriteCode(ctx *CodeWriteContext)
type DotFileLit ¶
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 ¶
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 ¶
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 (*EmbedExpr) ConfigFile ¶ added in v0.0.2
ConfigFile returns the config file path from the "config_file" named parameter.
func (*EmbedExpr) Excludes ¶ added in v0.0.2
Excludes returns the list of exclusion patterns from the "excludes" named parameter.
func (*EmbedExpr) ExcludesRe ¶ added in v0.0.2
ExcludesRe returns the list of regex exclusion patterns from the "excludes_re" named parameter.
func (*EmbedExpr) Includes ¶ added in v0.0.2
Includes returns the list of inclusion patterns from the "includes" named parameter.
func (*EmbedExpr) IncludesRe ¶ added in v0.0.2
IncludesRe returns the list of regex inclusion patterns from the "includes_re" named parameter.
func (*EmbedExpr) Path ¶
Path returns the file or directory path specified as the first argument to embed.
func (*EmbedExpr) Sources ¶ added in v0.0.2
Sources returns the list of source paths from the "sources" named parameter.
func (*EmbedExpr) Tree ¶ added in v0.0.2
Tree returns true if the "tree" flag is set, indicating recursive directory embedding.
func (*EmbedExpr) WriteCode ¶
func (e *EmbedExpr) WriteCode(ctx *CodeWriteContext)
type EmptyStmt ¶
EmptyStmt represents an empty statement.
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
// Meta is the optional `[k=v, …]` metadata block preceding the enum.
Meta *KeyValueArrayLit
}
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) 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
// Meta is the field's `[k=v, …]` metadata (or nil); read as `Enum.Item.@meta`.
Meta *KeyValueArrayLit
}
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>`.
type EnvLit ¶
EnvLit is the `env` contextual keyword: it yields the VM's environment variable table (a gad.Env). It is a keyword only as a standalone operand; as a member name (`x.env`) `env` is an ordinary identifier.
func (*EnvLit) WriteCode ¶
func (e *EnvLit) WriteCode(ctx *CodeWriteContext)
type ExportStmt ¶ added in v0.0.2
type ExportStmt struct {
TokenPos source.Pos
KeyExpr Expr
ValueExpr Expr
// Const marks an `export const NAME [= value]`: the exported member is a
// read-only module constant (assigning to it via the module is rejected).
Const bool
Doc *ast.CommentGroup // doc comment preceding the export; or nil
// Prelude is compiled before the export itself. It carries the `var name =
// init` declaration synthesized for `export prop name = init` (the live
// read/write binding), so the module gets a real local the exported prop's
// getter/setter close over.
Prelude Stmt
}
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 ExprSelector ¶
type ExprStmt ¶
type ExprStmt struct {
Expr Expr
}
ExprStmt represents an expression statement.
func (*ExprStmt) WriteCode ¶
func (s *ExprStmt) WriteCode(ctx *CodeWriteContext)
type FilesLit ¶
FilesLit is the `@files` keyword: the read-only source-name stack (an Array of SourceStackEntry) of the includes currently active, innermost last. When no include is active it is empty.
func (*FilesLit) WriteCode ¶
func (e *FilesLit) WriteCode(ctx *CodeWriteContext)
type FinallyStmt ¶
FinallyStmt represents an finally statement.
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 ¶
FlagLit represents a yes literal.
func (*FlagLit) WriteCode ¶
func (e *FlagLit) WriteCode(ctx *CodeWriteContext)
type FloatLit ¶
FloatLit represents a floating point literal.
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 (*ForInStmt) WriteCode ¶
func (s *ForInStmt) WriteCode(ctx *CodeWriteContext)
type ForStmt ¶
ForStmt represents a for statement.
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
// Meta is the optional `[k=v, …]` metadata block preceding the func; it
// compiles to a KeyValueArray on the function, read as `fn.@meta`.
Meta *KeyValueArrayLit
}
FuncExpr represents a function literal.
func (*FuncExpr) WriteCode ¶
func (e *FuncExpr) WriteCode(ctx *CodeWriteContext)
type FuncHeader ¶ added in v0.0.2
type FuncHeader struct {
NameExpr Expr
// TypeParams is the optional type-parameter list written between the name
// (or `func`) and the parameter list: `[T indexable, K int|uint, V number]`.
// Each entry names a type parameter and its constraint type(s); references to
// the name in a parameter/return type are substituted by the constraint at
// compile time.
TypeParams []*TypedIdentExpr
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) TypeParamsString ¶
func (e *FuncHeader) TypeParamsString() string
TypeParamsString renders the type-parameter list including brackets, or "" when there are none: `[T indexable, K int | uint]`.
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
// Meta is the `[k=v, …]` metadata carried onto the compiled function (used by
// class properties, whose accessor overload carries the member's metadata).
Meta *KeyValueArrayLit
}
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) ParamsEmpty ¶
func (m *FuncMethod) ParamsEmpty() bool
ParamsEmpty reports whether the accessor was declared with no parameters (`()`).
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 (*FuncStmt) End ¶ added in v0.0.2
End returns the position of first character immediately after the node.
func (*FuncStmt) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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 ProxyFuncType ¶
func ProxyFuncType() *FuncType
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
// Meta is the optional `[k=v, …]` metadata block preceding the func; it
// is the function's, read as `fn.@meta`.
Meta *KeyValueArrayLit
}
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) Params ¶ added in v0.0.2
func (d *GenDecl) Params() (positional []*ParamSpec, named []*NamedParamSpec)
func (*GenDecl) WriteCode ¶
func (d *GenDecl) WriteCode(ctx *CodeWriteContext)
type GlobalsLit ¶ added in v0.0.2
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
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 (*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 ¶
IdentExpr represents an identifier.
func EEmptyIdent ¶
func IdentOfSelector ¶ added in v0.0.2
func (*IdentExpr) WriteCode ¶
func (e *IdentExpr) WriteCode(ctx *CodeWriteContext)
type IdentList ¶
IdentList represents a list of identifiers.
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 (*IfStmt) WriteCode ¶
func (s *IfStmt) WriteCode(ctx *CodeWriteContext)
type ImportExpr ¶
type ImportExpr struct {
CallExpr
// Directive marks an import written as the statement `@import "m"`
// (`as name`, `{ … } from`): the formatter writes it back so.
Directive bool
// MainName marks `@import name from "m"`, the module's main as name
// (ParseImportMain): its pattern `{main: name}` is not written.
MainName bool
}
ImportExpr represents an import expression: `import("name"; params…)`.
A module name holding a glob meta character (`*`, `?`, `[…]`; `**` spans directories) imports every module it matches and yields an array of them, sorted by path — `import("./plugins/*.gad")`. The named args `@includes`, `@excludes`, `@includes_re` and `@excludes_re` filter the matches like embed's filters (`@`-prefixed since the other named args are module params); `*_test` files are skipped unless an include naming `_test` selects them.
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 ¶
IncDecStmt represents increment or decrement statement.
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 IncludeStmt ¶
type IncludeStmt struct {
IncludePos source.Pos
LParen source.Pos // valid for the parenthesized multi-file form
RParen source.Pos
Paths []*StrLit
// NamedArgs are the named args after `;` — the glob filters `includes`,
// `excludes`, `includes_re` and `excludes_re` of a glob path, as in embed
// (`include ("parts/*.gad"; excludes=["*_test.gad"])`).
NamedArgs CallExprNamedArgs
}
IncludeStmt is the `include` statement: it compiles one or more named source files inline into the current scope.
include "path.gad" // one file
include ("a.gad", "b.gad", …) // several, in order
include ("parts/*.gad"; excludes=["*_draft.gad"]) // every glob match
Unlike `import`, no module is created and no params are passed; each file's statements are emitted directly (wrapped so `@file`/`@files` report the source name while its code runs). A glob path includes every matching file in path order, narrowed by the includes/excludes/includes_re/excludes_re named args (as embed's; `*_test` files are skipped unless an include names `_test`).
func (*IncludeStmt) End ¶
func (s *IncludeStmt) End() source.Pos
End returns the position of first character immediately after the node.
func (*IncludeStmt) Pos ¶
func (s *IncludeStmt) Pos() source.Pos
Pos returns the position of first character belonging to the node.
func (*IncludeStmt) StmtNode ¶
func (s *IncludeStmt) StmtNode()
func (*IncludeStmt) String ¶
func (s *IncludeStmt) String() string
func (*IncludeStmt) WriteCode ¶
func (s *IncludeStmt) WriteCode(ctx *CodeWriteContext)
type IndexExpr ¶
IndexExpr represents an index expression.
func (*IndexExpr) WriteCode ¶
func (e *IndexExpr) WriteCode(ctx *CodeWriteContext)
type IntLit ¶
IntLit represents an integer literal.
func (*IntLit) WriteCode ¶
func (e *IntLit) WriteCode(ctx *CodeWriteContext)
type InterfaceContextFuncExpr ¶
type InterfaceContextFuncExpr struct {
FnExpr Expr // the context function (ident or selector, …)
Headers []*FuncHeaderExpr // required signature(s), anonymous
Block bool // written in the brace-block form `{ … }`
LBrace source.Pos
RBrace source.Pos
Doc *ast.CommentGroup
}
InterfaceContextFuncExpr is one entry of an interface's `funcs { … }` section: `FnExpr <(params)>` or `FnExpr { (params); … }`. It requires that the function value `FnExpr` (an ident, selector or any expression, captured by value where the interface is declared) has, for each header, a signature matching it — with the special `@self` positional param standing for the interface's own type. Every header must contain at least one `@self`.
func (*InterfaceContextFuncExpr) End ¶
func (e *InterfaceContextFuncExpr) End() source.Pos
func (*InterfaceContextFuncExpr) ExprNode ¶
func (e *InterfaceContextFuncExpr) ExprNode()
func (*InterfaceContextFuncExpr) Pos ¶
func (e *InterfaceContextFuncExpr) Pos() source.Pos
func (*InterfaceContextFuncExpr) String ¶
func (e *InterfaceContextFuncExpr) String() string
func (*InterfaceContextFuncExpr) WriteCode ¶
func (e *InterfaceContextFuncExpr) WriteCode(ctx *CodeWriteContext)
WriteCode writes one context-function entry `FnExpr <header>` (or the block form `FnExpr { (…); … }`). It is emitted inside the interface's `funcs { … }` section, so it carries no `:` prefix.
type InterfaceExpr ¶ added in v0.0.2
type InterfaceExpr struct {
InterfaceToken TokenLit
// ArrayDepth is the number of `[]` written after the interface name
// (`interface P [] { … }`, `interface P [][][] { … }`; anonymous
// `interface [] { … }`): the interface then matches an array nested to this
// depth whose leaf elements each satisfy the body (or ElemTypes). 0 for a
// plain interface.
ArrayDepth int
// ElemTypes are the leaf element types of an array-of-types interface,
// `interface P []<int|uint>` (or `interface P []int`): the named analogue of
// an anonymous `[]<int|uint>` array type. Such an interface has no body; nil
// otherwise. RAngle is the envelope's closing `>` (NoPos for a bare type).
ElemTypes []*TypeExpr
RAngle source.Pos
NameExpr Expr // *IdentExpr or nil (anonymous)
// TypeParams are a generic interface's type parameters — `interface
// Pair[K, V] { … }` —: a template, as a generic class's.
TypeParams []*TypedIdentExpr
// TypeArgs are, in a generic's instance (or its template), each type
// parameter and the types it is there, what `Iface.@tparams` reports. The
// compiler sets it; it is not written back.
TypeArgs []*TypedIdentExpr
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)
ContextFuncs []*InterfaceContextFuncExpr // context-function checks (`funcs { … }`)
// Rest is the `**<name>` rest-capture field: when the interface is used to
// cast a dict (`d ::: I`), keys not named by the interface are collected into
// a dict bound to this name in the result. Nil when the interface has none.
Rest *IdentExpr
RestDoc *ast.CommentGroup
// Spreads are the `**Expr` body items: members given at run time, EXPR
// evaluating to `{fields: …, methods: …}`, added where the interface is
// declared (see InterfaceSpread).
Spreads []Expr
LBrace source.Pos
RBrace source.Pos
Doc *ast.CommentGroup // doc comment preceding the interface; or nil
// Meta is the optional `[k=v, …]` metadata block preceding the interface.
Meta *KeyValueArrayLit
// Group marks the body of a group (`{ … }` in a body): its members are in
// the order written, never sorted by the formatter.
Group bool
}
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
// Meta is the optional `[k=v, …]` metadata block declared between the doc
// comment and the member; it compiles to a KeyValueArray reachable as
// `Iface.member.@meta`.
Meta *KeyValueArrayLit
// Group marks a field written as a group — `{ … }`, `? { … }` —: named
// `$N` (N its count in the body), typed by the anonymous interface of the
// block; it is written back as the block.
Group bool
}
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
// Meta is the optional `[k=v, …]` metadata block for this method.
Meta *KeyValueArrayLit
}
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 InterpolatedStringLit ¶
InterpolatedStringLit represents an interpolated string literal prefixed with `#`, such as `#"text"` or `#'symbol'`. It is parsed in ParseOperand when a token.InterpolatedString is followed by a string, raw string, heredoc, or symbol token. The Value field holds the string/symbol expression that follows the `#` token.
func (*InterpolatedStringLit) Build ¶
func (e *InterpolatedStringLit) Build(sourceStmts Stmts) (expr Expr, err error)
func (*InterpolatedStringLit) End ¶
func (e *InterpolatedStringLit) End() source.Pos
func (*InterpolatedStringLit) ExprNode ¶
func (e *InterpolatedStringLit) ExprNode()
func (*InterpolatedStringLit) Pos ¶
func (e *InterpolatedStringLit) Pos() source.Pos
func (*InterpolatedStringLit) String ¶
func (e *InterpolatedStringLit) String() string
func (*InterpolatedStringLit) StringValue ¶
func (e *InterpolatedStringLit) StringValue() string
func (*InterpolatedStringLit) StringValuePos ¶
func (e *InterpolatedStringLit) StringValuePos() source.Pos
StringValuePos returns the source position to pass to parser.ParseInterpolatedString: the position of the byte immediately before the first content byte of StringValue (the string 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 (*InterpolatedStringLit) WriteCode ¶
func (e *InterpolatedStringLit) WriteCode(ctx *CodeWriteContext)
type IsMainLit ¶ added in v0.0.2
IsMainLit represents an @main literal.
func (*IsMainLit) End ¶ added in v0.0.2
End IsMainLit the position of first character immediately after the node.
func (*IsMainLit) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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 ¶
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
IsElse reports whether this arm is the default `else` arm.
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
End returns the position of first character immediately after the node.
func (*MatchExpr) IsStmt ¶ added in v0.0.2
IsStmt reports whether the match uses statement-form (block) arms.
func (*MatchExpr) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
func (*MatchExpr) WriteCode ¶ added in v0.0.2
func (e *MatchExpr) WriteCode(ctx *CodeWriteContext)
type MetaTypeExpr ¶
type MetaTypeExpr struct {
TypePos source.Pos // position of the `type` keyword
Targets []*TypeExpr // the target types (one, or several for a union)
Gt source.Pos // position of the closing `>`
}
MetaTypeExpr is a `type<X>` (or `type<X|Y|…>`) meta-type written in a parameter-type position: it matches the TYPE VALUE X (a class or other object type) rather than an instance of X; a union `type<X|Y>` matches the type value X or Y. It lowers to one MetaType per target. (At an expression position `type <…>` is a TypeUnion instead; the meta form lives only where a parameter type is parsed.)
func (*MetaTypeExpr) End ¶
func (e *MetaTypeExpr) End() source.Pos
func (*MetaTypeExpr) ExprNode ¶
func (e *MetaTypeExpr) ExprNode()
func (*MetaTypeExpr) Pos ¶
func (e *MetaTypeExpr) Pos() source.Pos
func (*MetaTypeExpr) String ¶
func (e *MetaTypeExpr) String() string
func (*MetaTypeExpr) WriteCode ¶
func (e *MetaTypeExpr) 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 (s MixedTextStmtFlag) Has(f MixedTextStmtFlag) bool
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 ModLit ¶
ModLit is the `@mod` keyword: the current module object (an alias of `@module`). Inside an included file it is still the including module, since `include` compiles inline (no new module).
func (*ModLit) WriteCode ¶
func (e *ModLit) WriteCode(ctx *CodeWriteContext)
type ModuleLit ¶ added in v0.0.2
ModuleLit represents an @module literal.
func (*ModuleLit) End ¶ added in v0.0.2
End IsMainLit the position of first character immediately after the node.
func (*ModuleLit) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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 (b *NamedArgBuilder) Ident(v *IdentExpr) *NamedArgBuilder
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 ¶
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 ¶
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 ¶
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 ¶
NilLit represents an nil literal.
func (*NilLit) WriteCode ¶
func (e *NilLit) WriteCode(ctx *CodeWriteContext)
type NullishCallExpr ¶ added in v0.0.2
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 ¶
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
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
End returns the position of first character immediately after the node.
func (*OrExpr) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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) WriteCode ¶
func (s *ParamSpec) WriteCode(ctx *CodeWriteContext)
type ParenExpr ¶
ParenExpr represents a parenthesis wrapped expression.
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
End returns the position of first character immediately after the node.
func (*PropExpr) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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) { ... } }`.
type Ptr ¶ added in v0.0.2
func (*Ptr) WriteCode ¶ added in v0.0.2
func (e *Ptr) WriteCode(ctx *CodeWriteContext)
type PtrTypeExpr ¶
type PtrTypeExpr struct {
Star source.Pos
// Types are the types the pointed-to value may be.
Types []*TypeExpr
// Enveloped says the types were written inside `<…>`.
Enveloped bool
RAngle source.Pos
}
PtrTypeExpr is a pointer type written where a type goes: `*int`, `*array`, `*[]str`, `*<int|str>` — it accepts a `ptr` (see the `&` operator) whose current value is one of Types. As with an array type, one type needs no envelope: `*int` is the short form of `*<int>`.
func (*PtrTypeExpr) End ¶
func (e *PtrTypeExpr) End() source.Pos
func (*PtrTypeExpr) ExprNode ¶
func (e *PtrTypeExpr) ExprNode()
func (*PtrTypeExpr) Pos ¶
func (e *PtrTypeExpr) Pos() source.Pos
func (*PtrTypeExpr) String ¶
func (e *PtrTypeExpr) String() string
func (*PtrTypeExpr) WriteCode ¶
func (e *PtrTypeExpr) WriteCode(ctx *CodeWriteContext)
type RawHeredocLit ¶
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
func RawStr ¶ added in v0.0.2
RawStr builds a raw string literal node. value may be a raw content string or an already-quoted “ `…` “ / “ ```…``` “ literal (detected by a leading backtick); either way Value decodes and formatting emits a valid raw literal.
func (*RawStrLit) End ¶ added in v0.0.2
End returns the position of first character immediately after the node.
func (*RawStrLit) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
func (*RawStrLit) QuotedValue ¶ added in v0.0.2
func (*RawStrLit) WriteCode ¶ added in v0.0.2
func (e *RawStrLit) WriteCode(ctx *CodeWriteContext)
type RegexLit ¶ added in v0.0.2
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
End returns the position of first character immediately after the node.
func (*RegexLit) Pattern ¶ added in v0.0.2
Pattern returns the regex source between the delimiters, with `\/` unescaped.
func (*RegexLit) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
func (*RegexLit) Posix ¶ added in v0.0.2
Posix reports whether the literal carries the trailing `p` POSIX flag.
func (*RegexLit) WriteCode ¶ added in v0.0.2
func (e *RegexLit) WriteCode(ctx *CodeWriteContext)
type Return ¶
Return represents an return expression.
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 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 ¶
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 ¶
SliceExpr represents a slice expression.
func (*SliceExpr) WriteCode ¶
func (e *SliceExpr) WriteCode(ctx *CodeWriteContext)
type Spec ¶
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 ¶
type StdErrLit ¶
StdErrLit represents an STDERR literal.
func (*StdErrLit) WriteCode ¶
func (e *StdErrLit) WriteCode(ctx *CodeWriteContext)
type StdInLit ¶
StdInLit represents an STDIN literal.
func (*StdInLit) WriteCode ¶
func (e *StdInLit) WriteCode(ctx *CodeWriteContext)
type StdOutLit ¶
StdOutLit represents an STDOUT literal.
func (*StdOutLit) WriteCode ¶
func (e *StdOutLit) WriteCode(ctx *CodeWriteContext)
type Stmts ¶
type Stmts []Stmt
func (Stmts) WriteCode ¶
func (s Stmts) WriteCode(ctx *CodeWriteContext)
type StmtsExpr ¶
type StmtsExpr struct {
Stmts Stmts
}
func (*StmtsExpr) WriteCode ¶
func (s *StmtsExpr) WriteCode(ctx *CodeWriteContext)
type StrLit ¶ added in v0.0.2
type StrLit struct {
ValuePos source.Pos
Literal string
// Bare marks a name written without quotes — the selector of `x.name` —:
// it ends where the name does, not two quotes later.
Bare bool
}
StrLit represents a string literal.
func BareStr ¶
Str builds a cooked string literal node from a value; its Literal is the value encoded as a valid `"…"` literal, so formatting the node emits real code. BareStr is the name value, written without quotes at pos (a selector's).
func (*StrLit) End ¶ added in v0.0.2
End returns the position of first character immediately after the node.
func (*StrLit) InterpolationTemplate ¶
InterpolationTemplate returns the string value with standard escapes applied but the interpolation-delimiter escapes `\{` / `\}` preserved as `\{` / `\}`, so the interpolation parser (which strips them) treats those braces as literal text rather than interpolation delimiters. Used when compiling `#"…"`.
func (*StrLit) Pos ¶ added in v0.0.2
Pos returns the position of first character belonging to the node.
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 (*SymbolLit) WriteCode ¶ added in v0.0.2
func (s *SymbolLit) WriteCode(ctx *CodeWriteContext)
type TestKind ¶ added in v0.0.2
type TestKind uint8
TestKind selects whether a TestStmt declares a test or a benchmark.
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) WriteCode ¶ added in v0.0.2
func (s *TestStmt) WriteCode(ctx *CodeWriteContext)
type ThrowExpr ¶
ThrowExpr represents an throw expression.
func (*ThrowExpr) WriteCode ¶
func (s *ThrowExpr) WriteCode(ctx *CodeWriteContext)
type ThrowStmt ¶
ThrowStmt represents an throw statement.
func (*ThrowStmt) WriteCode ¶
func (s *ThrowStmt) WriteCode(ctx *CodeWriteContext)
type ToMultiParenConverter ¶
type ToMultiParenConverter interface {
Expr
ToMultiParenExpr() *MultiParenExpr
}
type ToRaw ¶ added in v0.0.2
func (*ToRaw) WriteCode ¶ added in v0.0.2
func (r *ToRaw) WriteCode(ctx *CodeWriteContext)
type TokenLit ¶ added in v0.0.2
func (TokenLit) Precedence ¶ added in v0.0.2
type TranspileOptions ¶
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 (*TryStmt) WriteCode ¶
func (s *TryStmt) WriteCode(ctx *CodeWriteContext)
type TypeArgsExpr ¶
TypeArgsExpr is a generic class or interface given its type arguments — `Box[int]`, `Pair[str, int]` —, where a type goes and where a value does. (One argument written as a value, `Box[int]`, parses as an IndexExpr; the compiler reads either against the generics in scope.)
func (*TypeArgsExpr) End ¶
func (e *TypeArgsExpr) End() source.Pos
End returns the position of first character immediately after the node.
func (*TypeArgsExpr) ExprNode ¶
func (e *TypeArgsExpr) ExprNode()
func (*TypeArgsExpr) Pos ¶
func (e *TypeArgsExpr) Pos() source.Pos
Pos returns the position of first character belonging to the node.
func (*TypeArgsExpr) String ¶
func (e *TypeArgsExpr) String() string
func (*TypeArgsExpr) WriteCode ¶
func (e *TypeArgsExpr) WriteCode(ctx *CodeWriteContext)
type TypeDeclStmt ¶
type TypeDeclStmt struct {
TypeLitExpr
}
TypeDeclStmt is the named statement form of a type literal — `class Name { … }`, `mixin Name { … }` or `type Name { … }` (the marker form). It wraps the TypeLitExpr (whose Mixin/Static flags say which) and compiles to `const Name = <the type literal>`.
func (*TypeDeclStmt) StmtNode ¶
func (*TypeDeclStmt) StmtNode()
type TypeLitExpr ¶
type TypeLitExpr struct {
ClassToken TokenLit
// Mixin marks a `mixin … { … }` literal: it parses like a class (parents,
// fields, props, methods) plus an optional `this` interface block, has no `new`
// clause, and lowers to `gad.Mixin(...)` instead of `Class(...)`.
Mixin bool
// Static marks a `type … { … }` marker-type literal: it parses like a class
// (static fields, props, methods) but has no instances — its members are on the
// type itself (`this` is the type), it may declare a `call(…)` factory instead
// of `new`, and it lowers to a StaticType.
Static bool
NameExpr Expr
// TypeParams are a generic class's type parameters — `class Box[T, K
// number] { … }` —, each a name and its optional constraint. A generic
// class is a template: each `Box[int]` the module uses is a class of its
// own, the parameters replaced by the arguments (see the compiler's
// generics).
TypeParams []*TypedIdentExpr
// TypeArgs are, in a generic's instance (or its template), each type
// parameter and the types it is there — `Box[int]`: T int —, what
// `Class.@tparams` reports. The compiler sets it; it is not written back.
TypeArgs []*TypedIdentExpr
// ImpliedName names an anonymous class a field is typed by (`a class { … }`)
// by its path from the outermost class holding it, that class's name first
// — `PageOptions.a.b`, `#1.a.b` below an anonymous one —, so an instance
// says where in the record it is. The compiler sets it. It is not written back (the source has no
// name there); NameExpr, when set, wins.
ImpliedName string
Parents []*ClassParentExpr
ExtendsDoc *ast.CommentGroup
// Use are the mixins a class pulls in (`use A, B`); class-only.
Use []Expr
UseDoc *ast.CommentGroup
Fields []*ClassFieldExpr
// Spreads are the `**Expr` body items of a class: members given at run
// time, EXPR evaluating to `{fields: …, methods: …, props: …}` (a dict or a
// key-value array), added after the declared ones.
Spreads []Expr
// This is a mixin's optional `this { … }` interface block: it declares the
// interface the `this` parameter of the mixin's props/methods must satisfy.
// Parsed as an anonymous interface body; mixin-only.
This *InterfaceExpr
ThisDoc *ast.CommentGroup
Props []*ClassMemberExpr
PropsDoc *ast.CommentGroup
New []*FuncMethod
NewDoc *ast.CommentGroup
// Call are a marker type's `call(…)` factory overloads (Static only); it is
// the analogue of `New` for a `type … { … }`, but the result is arbitrary (a
// factory), not an instance. Empty for classes and mixins.
Call []*FuncMethod
CallDoc *ast.CommentGroup
Methods []*ClassMemberExpr
MethodsDoc *ast.CommentGroup
LBrace source.Pos
RBrace source.Pos
Doc *ast.CommentGroup // doc comment preceding the class; or nil
// Meta is the optional `[k=v, …]` metadata block preceding the class.
Meta *KeyValueArrayLit
// Group marks the body of a group (`{ … }` in a body): its fields are in
// the order written — its columns —, never sorted by the formatter.
Group bool
}
TypeLitExpr is a type literal — a `class`, `mixin` or marker `type` body, distinguished by the Mixin / Static flags:
class [Name] { *P, …, fields, props {…}, new …, methods {…} }
mixin [Name] { … this {…} … } // Mixin
type [Name] { … call(…) … } // Static (marker: no instances)
Parent classes are `*Parent` spread body items (optionally aliased as `*Parent: Alias`), alongside fields and the `props`/`new`/`methods` groups. A class lowers (in the compiler) to a
Class(name; define=(Type, define) => define(; extends=…, fields=…,
props=…, 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 (*TypeLitExpr) End ¶
func (e *TypeLitExpr) End() source.Pos
func (*TypeLitExpr) ExprNode ¶
func (e *TypeLitExpr) ExprNode()
func (*TypeLitExpr) Pos ¶
func (e *TypeLitExpr) Pos() source.Pos
func (*TypeLitExpr) String ¶
func (e *TypeLitExpr) String() string
func (*TypeLitExpr) WriteCode ¶
func (e *TypeLitExpr) WriteCode(ctx *CodeWriteContext)
type TypeUnionExpr ¶
type TypeUnionExpr struct {
TypePos source.Pos // position of the `type` keyword
Types []*TypeExpr // the union members (at least one)
// Decl marks the union of a declaration — `type Name <T1|T2>` —, written
// back so; Meta is its `[k=v, …]` metadata, read as `Name.@meta`.
Decl bool
Meta *KeyValueArrayLit
}
TypeUnionExpr is a first-class type-union value written `type T1|T2|…` (e.g. `type int|uint`). It evaluates to a TypeUnion at run time; a value satisfies it when it satisfies any member. Members are the same type forms a parameter type accepts: named types, interfaces, method interfaces and func-header types.
func (*TypeUnionExpr) End ¶
func (e *TypeUnionExpr) End() source.Pos
func (*TypeUnionExpr) ExprNode ¶
func (e *TypeUnionExpr) ExprNode()
func (*TypeUnionExpr) Pos ¶
func (e *TypeUnionExpr) Pos() source.Pos
func (*TypeUnionExpr) String ¶
func (e *TypeUnionExpr) String() string
func (*TypeUnionExpr) WriteCode ¶
func (e *TypeUnionExpr) WriteCode(ctx *CodeWriteContext)
type TypedArrayTypeStmt ¶
type TypedArrayTypeStmt struct {
TypePos source.Pos
NameExpr *IdentExpr
// Depth is the number of `[]` written (>= 1).
Depth int
// ElemTypes are the element types (`<int|uint>` or a bare `int`); nil when the
// element is an inline interface (ElemIface).
ElemTypes []*TypeExpr
RAngle source.Pos // the envelope's closing `>`; NoPos for a bare type
// ElemIface is the inline interface element (`[]{ … }`); nil otherwise.
ElemIface *InterfaceExpr
Doc *ast.CommentGroup
// Meta is the optional `[k=v, …]` metadata block preceding the declaration.
Meta *KeyValueArrayLit
// Body is the optional class-like member block after the element
// (`type T []int { label str; new(…) {…}; props {…}; methods {…} }`): fields,
// constructor overloads, properties and methods (no parents, `use`, `this` or
// `call`). nil when there is none.
Body *TypeLitExpr
}
TypedArrayTypeStmt is a named typed-array type declaration:
type numerics []<int|uint|float|decimal> // element types in an envelope
type ints []int // one bare element type
type users []{ name; id } // an inline interface element
type users [] interface { name; id } // the same, long form
type grid [][]int // deeper nesting
It compiles to `const NAME = TypedArrayType("NAME", depth, elem; meta=…)`: a TypedArrayType whose instances (`numerics(1, 2.5)`) are typed arrays.
func (*TypedArrayTypeStmt) End ¶
func (s *TypedArrayTypeStmt) End() source.Pos
func (*TypedArrayTypeStmt) Pos ¶
func (s *TypedArrayTypeStmt) Pos() source.Pos
func (*TypedArrayTypeStmt) StmtNode ¶
func (s *TypedArrayTypeStmt) StmtNode()
func (*TypedArrayTypeStmt) String ¶
func (s *TypedArrayTypeStmt) String() string
func (*TypedArrayTypeStmt) WriteCode ¶
func (s *TypedArrayTypeStmt) WriteCode(ctx *CodeWriteContext)
WriteCode renders `type NAME []…ELEM`, the element as `int`, `<int | uint>` or `{ … }` (an inline interface; the long `interface { … }` form prints short).
type TypedIdentExpr ¶
type TypedIdentExpr struct {
Ident *IdentExpr
Type []*TypeExpr
// Nullable marks the identifier as accepting nil in addition to its declared
// types, written with a `?` after the name (`x? int`, `x? int|str`).
Nullable bool
}
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 PtrParam ¶
func PtrParam(e Expr) *TypedIdentExpr
PtrParam reinterprets `name * Type` — the way an expression parser reads a pointer-typed parameter such as `(p *array)`, which it cannot tell from a multiplication — as the typed identifier `name *Type`. It is used only where a parameter is expected (so `(a * b)` elsewhere stays a product); nil when e is not that shape.
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 ¶
UintLit represents an unsigned integer literal.
func (*UintLit) WriteCode ¶
func (e *UintLit) WriteCode(ctx *CodeWriteContext)
type UnaryExpr ¶
UnaryExpr represents an unary operator expression.
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) 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.
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 // colon form; nil for the block form
Body *BlockStmt // block form; nil for the colon form
}
WithExpr is the expression form `with Resource [as IDENT]: Value`: it enters the resource (gad.enter), evaluates Value, exits (gad.exit) and yields Value.
The block form `with Resource [as IDENT] { Body }` is also an expression: it enters the resource, runs Body (with IDENT bound to the resource), exits, and yields the resource itself. In that form Body is non-nil and Value is nil.
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) WriteCode ¶ added in v0.0.2
func (s *WithStmt) WriteCode(ctx *CodeWriteContext)