Help us shape the future of Go! Take the 2026 Go Developer Survey

syntax

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Range parser.Range
	Label string // empty for positional args; "account", "cap", etc. for labeled
	Value Value
}

Arg is a single argument to an instruction.

type Const

type Const struct {
	Range parser.Range
	Kind  ConstKind

	// Exactly one is set:
	StrVal  *string // raw quoted literal
	IntVal  *string // raw numeric string
	BoolVal *bool
}

Const is a constant literal: a string, an integer or a bool.

type ConstKind

type ConstKind int
const (
	ConstString ConstKind = iota
	ConstInt
	ConstBool
)

type Dest

type Dest struct {
	Range parser.Range
	Kind  DestKind
	Regs  []RegRef // non-empty for DestReg and DestList
}

Dest is the LHS of an assignment.

type DestKind

type DestKind int
const (
	DestReg     DestKind = iota // single register
	DestDiscard                 // _
	DestList                    // [$r0, $r1]
)

type Infix

type Infix struct {
	Range parser.Range
	Op    string // "+" or "-"
	Left  RegRef
	Right RegRef
}

Infix is a binary operation with infix syntax.

type InstrCall

type InstrCall struct {
	Range     parser.Range
	Name      string // e.g. "mk_monetary", "pull_account"
	TypeParam string // "" if none, else "int", "str", etc.
	Args      []Arg  // may be empty
}

InstrCall is a function-call instruction: name(args).

type InstrStmt

type InstrStmt struct {
	Range parser.Range

	// Dest is the destination; nil when the instruction has no dest (e.g. "set_current_asset($r3)").
	Dest *Dest

	// One of these is set:
	Call           *InstrCall // e.g. "mk_monetary($r0, $r1)"
	Const          *Const     // e.g. "$r0 = \"USD/2\"" or "$r0 = 42"
	Infix          *Infix     // e.g. "$r3 = $r1 + $r2"
	CompoundAssign *Infix     // e.g. "$r5 += $r9"  (Left is implicit from Dest)
}

InstrStmt represents one instruction line.

type LabelStmt

type LabelStmt struct {
	Range parser.Range
	Name  string
}

LabelStmt represents a label marker line, e.g. "#inorder_end_0".

type ParseResult

type ParseResult struct {
	Value  Program
	Errors []ParserError
}

func Parse

func Parse(input string) ParseResult

Parse parses an IR textual program and returns the AST.

type ParserError

type ParserError struct {
	Range parser.Range
	Msg   string
}

ParserError is a parse error with range information.

func (ParserError) Error

func (e ParserError) Error() string

type Program

type Program struct {
	Stmts []Stmt
}

Program is the root of the parsed IR text.

type RegRef

type RegRef struct {
	Range parser.Range
	Name  string
}

RegRef is a parsed register reference, e.g. "$r0".

type Stmt

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

Stmt is either a LabelStmt or an InstrStmt.

type Value

type Value struct {
	Range parser.Range
	Kind  ValueKind

	// Exactly one of these is set, depending on Kind:
	Reg   *RegRef   // ValReg
	Label *string   // ValLabel: the label name without '#'
	Int   *string   // ValInt: raw numeric string
	Regs  *[]RegRef // ValRegList
}

Value is a value that can appear as an argument.

type ValueKind

type ValueKind int
const (
	ValReg     ValueKind = iota // $r0
	ValLabel                    // #my_label
	ValInt                      // 42
	ValRegList                  // [$r0, $r1]
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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