ast

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package ast defines the Abstract Syntax Tree node types for the English programming language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	ElementType string // "number", "text", "boolean" — empty = infer from elements
	Elements    []Expression
}

ArrayLiteral is a typed homogeneous array literal: "an array of number [1, 2, 3]"

type AskExpression

type AskExpression struct {
	Prompt Expression // optional prompt to display
}

AskExpression reads a line of user input after displaying an optional prompt

type Assignment

type Assignment struct {
	Name  string
	Value Expression
	Line  int
}

Assignment represents a variable assignment

type BinaryExpression

type BinaryExpression struct {
	Left     Expression
	Operator string
	Right    Expression
}

BinaryExpression represents a binary operation (e.g., a + b)

type BooleanLiteral

type BooleanLiteral struct {
	Value bool
}

BooleanLiteral represents a boolean literal (true/false)

type BreakStatement

type BreakStatement struct{}

BreakStatement breaks out of a loop

type CallStatement

type CallStatement struct {
	FunctionCall *FunctionCall
	MethodCall   *MethodCall
	Line         int
}

CallStatement represents a function call as a statement

type CastExpression

type CastExpression struct {
	Value    Expression
	TypeName string
}

CastExpression casts a value to a type

type CommentStatement

type CommentStatement struct {
	Text string
}

CommentStatement carries a source comment through to the output. Text holds the comment body (everything after the leading '#', trimmed).

type ContinueStatement

type ContinueStatement struct{}

ContinueStatement skips the rest of the current loop iteration

type CopyExpression

type CopyExpression struct {
	Value Expression
}

CopyExpression creates a copy of a value

type ElseIfPart

type ElseIfPart struct {
	Condition Expression
	Body      []Statement
}

ElseIfPart represents an else-if branch

type ErrorTypeCheckExpression

type ErrorTypeCheckExpression struct {
	Value    Expression
	TypeName string
}

ErrorTypeCheckExpression checks whether an error value's type matches a named error type (including inherited types). Syntax: error is NetworkError

type ErrorTypeDecl

type ErrorTypeDecl struct {
	Name       string
	ParentType string // empty for root error types; parent name for subtypes
}

ErrorTypeDecl declares a custom error type. Syntax:

Declare NetworkError as an error type.
Declare CustomErr1 as a type of NetworkError.

type Expression

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

Expression is the interface for all expression nodes

type FieldAccess

type FieldAccess struct {
	Object Expression
	Field  string
}

FieldAccess accesses a field of a struct

type FieldAssignment

type FieldAssignment struct {
	ObjectName string
	Field      string
	Value      Expression
}

FieldAssignment assigns a value to a struct field

type ForEachLoop

type ForEachLoop struct {
	Item string
	List Expression
	Body []Statement
	Line int // source line of the loop-variable declaration
}

ForEachLoop represents a for-each loop over a collection

type ForLoop

type ForLoop struct {
	Count Expression
	Body  []Statement
	Line  int
}

ForLoop represents a counted for loop

type FunctionCall

type FunctionCall struct {
	Name      string
	Arguments []Expression
}

FunctionCall represents a function call expression

type FunctionDecl

type FunctionDecl struct {
	Name       string
	Parameters []string
	Body       []Statement
	Line       int
}

FunctionDecl represents a function declaration

type HasExpression

type HasExpression struct {
	Table Expression
	Key   Expression
}

HasExpression checks whether a lookup table contains a key: "TABLE has KEY"

type Identifier

type Identifier struct {
	Name string
}

Identifier represents a variable reference

type IfStatement

type IfStatement struct {
	Condition Expression
	Then      []Statement
	ElseIf    []*ElseIfPart
	Else      []Statement
	Line      int
}

IfStatement represents an if-then-else statement

type ImportStatement

type ImportStatement struct {
	Path      string   // The file path to import
	Items     []string // Specific items to import (empty means import all)
	ImportAll bool     // True for "import everything/all"
	IsSafe    bool     // True for safe imports (don't run top-level code)
}

ImportStatement represents an import statement

type IndexAssignment

type IndexAssignment struct {
	ListName string
	Index    Expression
	Value    Expression
	Line     int
}

IndexAssignment represents assigning to an array index

type IndexExpression

type IndexExpression struct {
	List  Expression
	Index Expression
}

IndexExpression represents array indexing (e.g., list[0])

type LengthExpression

type LengthExpression struct {
	List Expression
}

LengthExpression represents getting the length of a list or string

type ListLiteral

type ListLiteral struct {
	Elements []Expression
}

ListLiteral represents a list/array literal

type LocationExpression

type LocationExpression struct {
	Name string
}

LocationExpression returns the memory address of a variable

type LookupKeyAccess

type LookupKeyAccess struct {
	Table Expression
	Key   Expression
}

LookupKeyAccess reads a value from a lookup table: "TABLE at KEY" or "the entry KEY in TABLE"

type LookupKeyAssignment

type LookupKeyAssignment struct {
	TableName string
	Key       Expression
	Value     Expression
	Line      int
}

LookupKeyAssignment sets a value in a lookup table: "Set TABLE at KEY to be VALUE." or "Set the entry KEY in TABLE to be VALUE."

type LookupTableLiteral

type LookupTableLiteral struct{}

LookupTableLiteral creates an empty lookup table: "a lookup table"

type MethodCall

type MethodCall struct {
	Object     Expression
	MethodName string
	Arguments  []Expression
}

MethodCall represents calling a method on an object

type NilCheckExpression

type NilCheckExpression struct {
	Value            Expression
	IsSomethingCheck bool // true = "is something"; false = "is nothing"
}

NilCheckExpression checks whether a value is something (not nil) or nothing (nil).

  • IsSomethingCheck == true → "x is something" / "x has a value" (returns true when x != nil)
  • IsSomethingCheck == false → "x is nothing" / "x has no value" (returns true when x == nil)

type Node

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

Node is the base interface for all AST nodes

type NothingLiteral

type NothingLiteral struct{}

NothingLiteral represents a null/nil value (nothing, none, null)

type NumberLiteral

type NumberLiteral struct {
	Value float64
}

NumberLiteral represents a numeric literal

type OutputStatement

type OutputStatement struct {
	Values  []Expression
	Newline bool // true for Print, false for Write
	Line    int
}

OutputStatement represents a print statement

type Program

type Program struct {
	Statements []Statement

	// PolitenessStats is populated by the parser when it processes statements.
	// PoliteCount is the number of top-level statements prefixed with a
	// politeness marker (please / kindly / could you / would you kindly).
	// TotalCount is the total number of countable top-level statements
	// (comments are excluded).  ImpoliteLines records the source line of
	// every impolite statement for use in error reporting.
	PoliteCount   int
	TotalCount    int
	ImpoliteLines []int
}

Program is the root node of the AST

type RaiseStatement

type RaiseStatement struct {
	Message   Expression
	ErrorType string // Optional error type
	Line      int
}

RaiseStatement raises an error

type ReferenceExpression

type ReferenceExpression struct {
	Name string
}

ReferenceExpression creates a reference to a variable

type ReturnStatement

type ReturnStatement struct {
	Value Expression
	Line  int
}

ReturnStatement represents a return statement

type Statement

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

Statement is the interface for all statement nodes

type StringLiteral

type StringLiteral struct {
	Value string
}

StringLiteral represents a string literal

type StructDecl

type StructDecl struct {
	Name    string
	Fields  []*StructField
	Methods []*FunctionDecl
}

StructDecl represents a struct type declaration

type StructField

type StructField struct {
	Name         string
	TypeName     string
	DefaultValue Expression
	IsUnsigned   bool
}

StructField represents a field in a struct definition

type StructInstantiation

type StructInstantiation struct {
	StructName  string
	FieldValues map[string]Expression
	FieldOrder  []string // Maintain field order
}

StructInstantiation creates a new instance of a struct

type SwapStatement

type SwapStatement struct {
	Name1 string
	Name2 string
	Line  int
}

SwapStatement swaps two variables

type ToggleStatement

type ToggleStatement struct {
	Name string
	Line int
}

ToggleStatement toggles a boolean variable

type TryStatement

type TryStatement struct {
	TryBody     []Statement
	ErrorVar    string // Variable name to bind the error to
	ErrorType   string // If non-empty, only catch errors of this type
	ErrorBody   []Statement
	FinallyBody []Statement
	Line        int
}

TryStatement represents try/error/finally block

type TypeExpression

type TypeExpression struct {
	Value Expression
}

TypeExpression gets the type of a value

type TypedVariableDecl

type TypedVariableDecl struct {
	Name       string
	TypeName   string
	IsConstant bool
	Value      Expression
	Line       int
}

TypedVariableDecl represents a variable declaration with explicit type

type UnaryExpression

type UnaryExpression struct {
	Operator string
	Right    Expression
}

UnaryExpression represents a unary operation (e.g., -x)

type VariableDecl

type VariableDecl struct {
	Name       string
	IsConstant bool
	Value      Expression
	Line       int
}

VariableDecl represents a variable declaration

type WhileLoop

type WhileLoop struct {
	Condition Expression
	Body      []Statement
	Line      int
}

WhileLoop represents a while loop

Jump to

Keyboard shortcuts

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