pub enum Stmt {
Show 19 variants
Assign(String, Expr),
Expr(Expr),
If {
cond: Expr,
body: Vec<(Stmt, bool)>,
elseif_branches: Vec<(Expr, Vec<(Stmt, bool)>)>,
else_body: Option<Vec<(Stmt, bool)>>,
},
For {
var: String,
range_expr: Expr,
body: Vec<(Stmt, bool)>,
},
While {
cond: Expr,
body: Vec<(Stmt, bool)>,
},
Break,
Continue,
Switch {
expr: Expr,
cases: Vec<(Vec<Expr>, Vec<(Stmt, bool)>)>,
otherwise_body: Option<Vec<(Stmt, bool)>>,
},
DoUntil {
body: Vec<(Stmt, bool)>,
cond: Expr,
},
FunctionDef {
name: String,
outputs: Vec<String>,
params: Vec<String>,
body_source: String,
doc: Option<String>,
},
Return,
MultiAssign {
targets: Vec<String>,
expr: Expr,
},
TryCatch {
try_body: Vec<(Stmt, bool)>,
catch_var: Option<String>,
catch_body: Vec<(Stmt, bool)>,
},
CellSet(String, Expr, Expr),
FieldSet(String, Vec<String>, Expr),
StructArrayFieldSet(String, Expr, Vec<String>, Expr),
IndexSet {
name: String,
indices: Vec<Expr>,
value: Expr,
},
Global(Vec<String>),
Persistent(Vec<String>),
}Expand description
Top-level statement returned by parse and parse_stmts.
Variants§
Assign(String, Expr)
Variable assignment: name = expr
Expr(Expr)
Standalone expression — result goes into ans
If
if cond; body; elseif cond; ...; else; ...; end
Fields
For
for var = range_expr; body; end — iterates over columns of the range matrix
Fields
While
while cond; body; end
Fields
Break
break — exits the innermost enclosing loop
Continue
continue — advances to next iteration of the innermost enclosing loop
Switch
switch expr; case val; body; ...; otherwise; body; end
Each case carries a list of match expressions (single value today; cell-array
multi-value is deferred to Phase 11.5b) and a statement body.
otherwise is optional.
Fields
DoUntil
do; body; until (cond) — Octave-specific post-test loop.
The body always executes at least once. break and continue work as in while.
Fields
FunctionDef
function [outputs] = name(params) body end — named user function definition.
The body is stored as raw source text and re-parsed on each call by exec.rs.
Named functions execute in an isolated scope (only params and built-in constants visible).
Fields
Return
return — exits the current function immediately.
Inside a named function, return causes the function to return its current output
variable values. At the top level it is treated as an error by exec.rs.
MultiAssign
[a, b] = f() — multi-output assignment.
Produced when the LHS is a bracket list of identifiers.
The RHS must evaluate to a Value::Tuple; extra values are discarded,
missing values produce an error.
Fields
targets: Vec<String>The list of output variable names on the LHS (e.g. ["a", "b"] in [a, b] = f()).
expr: ExprThe RHS expression — must evaluate to Value::Tuple.
TryCatch
try; body; catch [e]; catch_body; end — protected block.
If catch_var is Some(name), the catch variable is bound to a struct
with field message containing the error string.
Fields
CellSet(String, Expr, Expr)
c{i} = v — cell element assignment.
Updates element i (1-based) of the cell array named name.
FieldSet(String, Vec<String>, Expr)
s.x = v / s.a.b = v — struct field assignment.
FieldSet(base_var, field_path, rhs):
base_var: the top-level variable name (e.g."s").field_path: one or more field names leading to the target (e.g.["x"]or["a", "b"]).rhs: the value to store.
At runtime the base variable is loaded (or a fresh empty struct is created), the path is walked (creating intermediate structs on demand), and the final field is set.
StructArrayFieldSet(String, Expr, Vec<String>, Expr)
s(i).field = v / s(i).a.b = v — struct array element field assignment.
StructArrayFieldSet(base_var, idx_expr, field_path, rhs):
base_var: the top-level variable name (e.g."s").idx_expr: the 1-based integer index expression (e.g.1ori+1).field_path: one or more field names (e.g.["x"]or["a", "b"]).rhs: the value to store.
At runtime the struct array is loaded (or created), grown if necessary,
and the field of element idx is set.
IndexSet
v(i) = x, A(i,j) = x, v(1:3) = [1 2 3] — indexed assignment.
Modifies one or more elements of an existing matrix (or creates/grows it).
Index expressions follow the same syntax as the read-path (Phase 6):
:, scalars, ranges, and logical masks (Phase 15d).
A scalar RHS is broadcast to all selected positions.
Fields
Global(Vec<String>)
global x y z — declares names as globally shared across function scopes.
Any function that declares the same names as global shares the same storage.
At the top level (REPL/script), global variables are initialized in the shared
store and behave like ordinary workspace variables.
Persistent(Vec<String>)
persistent x y z — declares names as persistent across calls to the enclosing function.
The values are retained between calls. On the first call the variables are initialized to an empty/zero state; on subsequent calls the saved state is restored. Valid only inside a named function; at the top level it is accepted but has no effect.