Documentation
¶
Overview ¶
Package parser defines the AST node types for MX Script and the recursive-descent parser that builds an AST from a token stream.
Package parser implements a recursive-descent parser that converts a stream of tokens (produced by the lexer) into an MX Script AST.
visit.go — utilities for walking an AST. Used by tooling (formatter, coverage reporter, future LSP enhancements) that need to enumerate every statement / expression position.
Index ¶
- func ExecutableLines(prog *Program) map[int]bool
- type ArrayLit
- type AssignStmt
- type BenchDecl
- type BinaryExpr
- type BoolLit
- type BreakStmt
- type CallExpr
- type ContinueStmt
- type DestructureBinding
- type DestructurePattern
- type Expr
- type ExprStmt
- type FnDecl
- type FnLit
- type GroupStmt
- type Identifier
- type IfStmt
- type ImportStmt
- type IndexExpr
- type LetStmt
- type LoopStmt
- type MatchArm
- type MatchExpr
- type MemberExpr
- type MiddlewareDecl
- type Node
- type NullLit
- type NumberLit
- type ObjectLit
- type ObjectPair
- type ParseError
- type Parser
- type Program
- type RangeExpr
- type ReturnStmt
- type RouteDecl
- type ServerBlock
- type SpawnStmt
- type SpreadExpr
- type StaticStmt
- type Stmt
- type StringLit
- type TestDecl
- type TryExpr
- type TryStmt
- type UnaryExpr
- type UseStmt
- type WhileStmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecutableLines ¶ added in v0.31.0
ExecutableLines walks the program and returns the set of source-line numbers that carry an executable statement. The coverage reporter compares this against the lines that actually ran.
Types ¶
type AssignStmt ¶
type BenchDecl ¶ added in v1.32.0
BenchDecl is `bench "name" { ... }` — the benchmarking sibling of TestDecl. `mx bench` discovers them, runs the body in a calibrated loop, and reports ops/sec.
type BinaryExpr ¶
type BreakStmt ¶ added in v0.2.0
type BreakStmt struct {
// contains filtered or unexported fields
}
BreakStmt exits the nearest enclosing loop.
type ContinueStmt ¶ added in v0.2.0
type ContinueStmt struct {
// contains filtered or unexported fields
}
ContinueStmt jumps to the next iteration of the nearest enclosing loop.
type DestructureBinding ¶ added in v0.28.0
type DestructureBinding struct {
Name string
Source string // empty unless renamed
Default Expr // nil if no default
Rest bool // array spread
}
DestructureBinding represents one position in a destructure pattern:
{ name } -> Name="name", Source="name"
{ name: n } -> Name="n", Source="name"
{ name = "anon" } -> Name="name", Source="name", Default=<expr>
{ name: n = "anon" } -> Name="n", Source="name", Default=<expr>
[a] -> Name="a"
[...rest] -> Name="rest", Rest=true
[a = 0] -> Name="a", Default=<expr>
type DestructurePattern ¶ added in v0.27.0
type DestructurePattern struct {
IsArray bool // false = object, true = array
Items []DestructureBinding // each binding's source key + local name + optional default
}
DestructurePattern captures `let { a, b }` or `let [a, b]` style bindings.
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr is the type implemented by all expression nodes.
type FnDecl ¶
type GroupStmt ¶ added in v0.39.0
GroupStmt nests a set of routes under a shared path prefix and an optional shared list of middlewares. e.g.:
group /api/v1 {
use require_auth
get /users { ... }
get /users/:id { ... }
}
type Identifier ¶
type Identifier struct {
Name string
// contains filtered or unexported fields
}
type ImportStmt ¶
type ImportStmt struct {
Path string
As string // empty for flat import, non-empty for namespaced
// contains filtered or unexported fields
}
ImportStmt represents either a flat import (everything dumped into the current scope) or a namespaced one:
import "./utils.mx" // everything top-level becomes globally available import "./auth.mx" as auth // exports become auth.login(), auth.signup()
When `As` is non-empty, only top-level `let` bindings and `fn` declarations from the imported file are exposed, and they're hung off an object named `As` in the importing file's scope.
type LetStmt ¶
type LetStmt struct {
Name string // single-binding form: `let x = ...`
Pattern *DestructurePattern // destructure form: `let {a,b} = ...` / `let [a,b] = ...`
Value Expr
// Type is an optional annotation — `let x: int = 5`. Decorative
// today; surfaced in LSP hover and `mx docs` so callers know what
// shape to expect. Empty string means "no annotation".
Type string
// contains filtered or unexported fields
}
type LoopStmt ¶
type LoopStmt struct {
Iterable Expr
IndexVar string
Var string
Body []Stmt
// contains filtered or unexported fields
}
LoopStmt is `loop iterable as item { ... }` or `loop iterable as i, item { ... }`. IndexVar is the empty string when no index is requested.
type MatchExpr ¶ added in v0.5.0
MatchExpr is `match subject { p1 => e1, p2 => e2, _ => e3 }`. Arms are tested top-to-bottom; the first matching arm's body is the result. A pattern is either an expression (compared with `==`) or the bare identifier `_` which matches anything.
type MemberExpr ¶
type MiddlewareDecl ¶
type ObjectLit ¶
type ObjectLit struct {
Pairs []ObjectPair
// contains filtered or unexported fields
}
type ObjectPair ¶
type ParseError ¶ added in v0.2.0
ParseError carries a structured location so the CLI can render source-context errors with a caret pointer.
func (*ParseError) Error ¶ added in v0.2.0
func (e *ParseError) Error() string
type RangeExpr ¶ added in v1.37.0
type RangeExpr struct {
Start Expr
End Expr
Inclusive bool
// contains filtered or unexported fields
}
RangeExpr is `start..end` (exclusive) or `start..=end` (inclusive). Materialises to an array of integers — usable on the RHS of `loop`, `for`, anywhere an iterable is expected.
type ReturnStmt ¶
type ReturnStmt struct {
Value Expr // nil if `return` with no value
// contains filtered or unexported fields
}
type RouteDecl ¶
type ServerBlock ¶
type ServerBlock struct {
Settings []ObjectPair
// contains filtered or unexported fields
}
type SpawnStmt ¶ added in v0.16.0
type SpawnStmt struct {
Body []Stmt
// contains filtered or unexported fields
}
SpawnStmt runs a block in a fresh goroutine. The body shares the enclosing closure (read-only by convention — writes from goroutines race with the main interpreter and other spawns). Use channels for inter-goroutine communication.
type SpreadExpr ¶ added in v0.3.0
type SpreadExpr struct {
Inner Expr
// contains filtered or unexported fields
}
SpreadExpr wraps an expression that should be expanded inline inside an array literal, an object literal, or a call argument list.
type StaticStmt ¶ added in v0.3.0
type StaticStmt struct {
Dir string
Mount string // URL prefix; defaults to "/" if not specified
// contains filtered or unexported fields
}
StaticStmt declares a static-file mount point.
static "./public" // serves files from ./public at / static "./assets" at "/cdn" // serves files from ./assets at /cdn
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt is the type implemented by all statement / top-level declaration nodes.
type TestDecl ¶ added in v1.29.0
TestDecl is `test "name" { ... }` — an inline test block discovered by `mx test`. The body is evaluated in a fresh scope per test; failures are reported via assert() / panic. Position is the location of the `test` keyword for nice error messages.
type TryExpr ¶ added in v0.7.0
type TryExpr struct {
Try []Stmt
CatchVar string
Catch []Stmt
// contains filtered or unexported fields
}
TryExpr is the expression form of try/catch. The value of the last expression statement in whichever block ran becomes the result.
let parsed = try { json_parse(input) } catch (e) { { error: e.message } }