ast

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ast defines the lossless syntax tree. It intentionally contains a NativeStatement node: Ruby/Rails DSLs are open ended, so Ruby-only constructs can survive parsing without weakening the typed, portable subset.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	Base
	Elements []Expression
}

type AssignmentStatement

type AssignmentStatement struct {
	Base
	Target   Expression
	Operator string
	Value    Expression
}

type AttemptExpression added in v0.2.0

type AttemptExpression struct {
	Base
	Value Expression
	Body  []Statement
}

AttemptExpression is recovery-only for pre-0.3 source. The parser diagnoses every authored attempt expression before later compiler phases can run it. Exactly one of Value and Body is populated while recovery is still present.

type Attribute

type Attribute struct {
	Base
	Name      string
	Arguments []CallArgument
}

type Base

type Base struct {
	SourceSpan      token.Span
	TrailingComment string
}

func (Base) Span

func (b Base) Span() token.Span

type BinaryExpression

type BinaryExpression struct {
	Base
	Left     Expression
	Operator string
	Right    Expression
}

type BlankStatement

type BlankStatement struct{ Base }

type BlockExpression

type BlockExpression struct {
	Base
	Parameters []string
	Body       []Statement
	Brace      bool
}

type BreakStatement

type BreakStatement struct{ Base }

type CallArgument

type CallArgument struct {
	Name  string
	Value Expression
	Splat string
}

type CallExpression

type CallExpression struct {
	Base
	Callee    Expression
	Arguments []CallArgument
	Block     *BlockExpression
}

type CaseBranch

type CaseBranch struct {
	Base
	Value        Expression
	Alternatives []Expression
	Bindings     []PatternBinding
	Body         []Statement
}

type CaseStatement

type CaseStatement struct {
	Base
	Value    Expression
	Leading  []Statement
	Branches []CaseBranch
	Else     []Statement
	HasElse  bool
}

type CatchExpression added in v0.3.0

type CatchExpression struct {
	Base
	Value   Expression
	Binding PatternBinding
	Body    []Statement
}

CatchExpression unwraps a Result-producing Value or evaluates Body for its Err payload. Body is retained as statements because it may either recover with a final expression or transfer control with return, break, or next.

type ClassStatement

type ClassStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Superclass     Expression
	Implements     []TypeRef
	Body           []Statement
}

type CommentStatement

type CommentStatement struct {
	Base
	Text string
}

type EnumMemberStatement

type EnumMemberStatement struct {
	Base
	Name       string
	Parameters []Parameter
	RawValue   Expression
}

type EnumStatement

type EnumStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Body           []Statement
}

EnumStatement is a closed nominal set of values. Members remain statements so their source spans and comments survive the syntax and formatting passes.

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Base
	Expression Expression
}

type FieldStatement

type FieldStatement struct {
	Base
	Name     string
	Type     TypeRef
	Value    Expression
	ReadOnly bool
}

type GenericExpression

type GenericExpression struct {
	Base
	Receiver  Expression
	Arguments []TypeRef
}

type HashEntry

type HashEntry struct {
	Key   Expression
	Value Expression
}

type HashLiteral

type HashLiteral struct {
	Base
	Entries []HashEntry
}

type Identifier

type Identifier struct {
	Base
	Name string
}

type IfBranch

type IfBranch struct {
	Condition Expression
	Body      []Statement
}

type IfStatement

type IfStatement struct {
	Base
	Condition Expression
	Then      []Statement
	ElseIf    []IfBranch
	Else      []Statement
	HasElse   bool
}

type ImportStatement

type ImportStatement struct {
	Base
	Path     string
	PathSpan token.Span
	Symbols  []string
	Alias    string
}

type IndexExpression

type IndexExpression struct {
	Base
	Receiver Expression
	Index    Expression
}

type InterfaceStatement

type InterfaceStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Methods        []*MethodStatement
}

type InterpolatedString

type InterpolatedString struct {
	Base
	Raw   string
	Parts []StringPart
}

type IterationExpression

type IterationExpression struct {
	Base
	Source    Expression
	Operation string
	SliceSize Expression
	Initial   Expression
	WithIndex bool
	Block     *BlockExpression
}

IterationExpression is the portable, Ruby-shaped collection iteration syntax. It remains an expression in the syntax tree so the original block delimiters can be retained, then lowers to structured iteration IR instead of a target-language callback.

type JSXAttribute added in v0.2.3

type JSXAttribute struct {
	Base
	Name    string
	Value   Expression
	Boolean bool
}

type JSXChild added in v0.2.3

type JSXChild interface {
	Node
	// contains filtered or unexported methods
}

type JSXElement added in v0.2.3

type JSXElement struct {
	Base
	Name       string
	Component  Expression
	Attributes []JSXAttribute
	Children   []JSXChild
	Fragment   bool
}

JSXElement is a provider-backed expression parsed into the shared AST. Intrinsic elements keep Name only; component elements additionally retain a normal TypeRB expression so imports and function references remain typed.

type JSXExpression added in v0.2.3

type JSXExpression struct {
	Base
	Value Expression
}

type JSXText added in v0.2.3

type JSXText struct {
	Base
	Text string
}

type LambdaExpression added in v0.2.3

type LambdaExpression struct {
	Base
	Parameters []Parameter
	ReturnType TypeRef
	// Fails is recovery-only for pre-0.3 lambda signatures.
	Fails TypeRef
	Body  []Statement
}

LambdaExpression is a typed, lexically scoped function value. Unlike an iteration block, it owns return statements and can outlive its declaration.

type Literal

type Literal struct {
	Base
	Kind LiteralKind
	Raw  string
}

type LiteralKind

type LiteralKind string
const (
	StringLiteral  LiteralKind = "string"
	IntegerLiteral LiteralKind = "integer"
	FloatLiteral   LiteralKind = "float"
	BooleanLiteral LiteralKind = "boolean"
	NilLiteral     LiteralKind = "nil"
)

type MemberExpression

type MemberExpression struct {
	Base
	Receiver  Expression
	Name      string
	Safe      bool
	Namespace bool
}

type MethodStatement

type MethodStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Parameters     []Parameter
	ReturnType     TypeRef
	// Fails is recovery-only for pre-0.3 source. The parser diagnoses every
	// authored effect signature before later compiler phases can run it.
	Fails TypeRef
	Body  []Statement
	Class bool
}

type ModuleStatement

type ModuleStatement struct {
	Base
	Name string
	Body []Statement
}

type NativeBlock

type NativeBlock struct {
	Base
	Header string
	Body   []Statement
	Closer string
}

type NativeExpression

type NativeExpression struct {
	Base
	Text string
}

type NativeStatement

type NativeStatement struct {
	Base
	Text string
}

NativeStatement and NativeBlock are explicit Ruby interoperability nodes. They are rejected by portable backends with a precise diagnostic.

type NextStatement

type NextStatement struct{ Base }

type Node

type Node interface {
	Span() token.Span
}

type Parameter

type Parameter struct {
	Base
	Name        string
	Type        TypeRef
	Default     Expression
	Keyword     bool
	Rest        bool
	KeywordRest bool
}

type PatternBinding

type PatternBinding struct {
	Base
	Name string
}

PatternBinding is a name introduced by a payload enum pattern. The payload type comes from the matched enum member and is attached in typed IR.

type Program

type Program struct {
	Base
	Mode              string
	Package           string
	ModulePath        string
	GoModule          string
	RubyLoader        string
	TypeScriptRuntime string
	Statements        []Statement
	Tokens            []token.Token
}

type RangeExpression

type RangeExpression struct {
	Base
	Start     Expression
	End       Expression
	Exclusive bool
}

type RecordFieldStatement

type RecordFieldStatement struct {
	Base
	Name       string
	Type       TypeRef
	Attributes []Attribute
}

type RecordStatement

type RecordStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Body           []Statement
}

RecordStatement is a closed product type. Unlike ClassStatement it has keyword-only construction, public data fields, value semantics, and no inheritance. Backends lower it to their native data representation.

type ReturnStatement

type ReturnStatement struct {
	Base
	Value Expression
}

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type StringPart

type StringPart struct {
	Text       string
	Expression Expression
}

type SymbolLiteral

type SymbolLiteral struct {
	Base
	Name string
	Raw  string
}

type TryExpression added in v0.3.0

type TryExpression struct {
	Base
	Value Expression
}

TryExpression propagates the Err payload of a Result-producing Value from the nearest compatible result boundary. The checker attaches that boundary after parsing; the syntax tree retains only the authored operand.

type TypeAliasStatement added in v0.2.0

type TypeAliasStatement struct {
	Base
	Name           string
	TypeParameters []TypeParameter
	Target         TypeRef
}

TypeAliasStatement declares a transparent source-level alias. The target is retained in the syntax tree so tooling can show the authored name while the checker compares the expanded type.

type TypeParameter

type TypeParameter struct {
	Base
	Name string
}

type TypeRef

type TypeRef struct {
	Base
	Name               string
	Arguments          []TypeRef
	Union              []TypeRef
	FunctionParameters []TypeRef
	FunctionReturn     *TypeRef
	// FunctionFails is recovery-only for pre-0.3 function types.
	FunctionFails *TypeRef
	Nullable      bool
	Array         bool
}

func (TypeRef) Empty

func (t TypeRef) Empty() bool

func (TypeRef) String

func (t TypeRef) String() string

type UnaryExpression

type UnaryExpression struct {
	Base
	Operator string
	Operand  Expression
}

type VariableStatement

type VariableStatement struct {
	Base
	Name     string
	Type     TypeRef
	Value    Expression
	Mutable  bool
	Constant bool
}

type WhileStatement

type WhileStatement struct {
	Base
	Condition Expression
	Body      []Statement
}

Jump to

Keyboard shortcuts

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