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.
Index ¶
- type ArrayLit
- type AssignStmt
- type BinaryExpr
- type BoolLit
- type BreakStmt
- type CallExpr
- type ContinueStmt
- type DestructurePattern
- type Expr
- type ExprStmt
- type FnDecl
- type FnLit
- 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 ReturnStmt
- type RouteDecl
- type ServerBlock
- type SpawnStmt
- type SpreadExpr
- type StaticStmt
- type Stmt
- type StringLit
- type TryExpr
- type TryStmt
- type UnaryExpr
- type UseStmt
- type WhileStmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignStmt ¶
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 DestructurePattern ¶ added in v0.27.0
type DestructurePattern struct {
IsArray bool // false = object, true = array
Names []string // names to bind in order (object: matches keys; array: positional)
}
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 Identifier ¶
type Identifier struct {
Name string
// contains filtered or unexported fields
}
type ImportStmt ¶
type ImportStmt struct {
Path string
// contains filtered or unexported fields
}
type LetStmt ¶
type LetStmt struct {
Name string // single-binding form: `let x = ...`
Pattern *DestructurePattern // destructure form: `let {a,b} = ...` / `let [a,b] = ...`
Value Expr
// 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 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 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 } }