Skip to main content

Stmt

Enum Stmt 

Source
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

§cond: Expr

The condition expression evaluated to decide which branch to take.

§body: Vec<(Stmt, bool)>

Statements to execute when cond is truthy.

§elseif_branches: Vec<(Expr, Vec<(Stmt, bool)>)>

Zero or more elseif (cond) body branches, in source order.

§else_body: Option<Vec<(Stmt, bool)>>

Statements to execute when no condition matched, or None if there is no else.

§

For

for var = range_expr; body; end — iterates over columns of the range matrix

Fields

§var: String

The loop variable assigned on each iteration.

§range_expr: Expr

Expression that produces the matrix whose columns are iterated.

§body: Vec<(Stmt, bool)>

Loop body statements.

§

While

while cond; body; end

Fields

§cond: Expr

Loop condition — re-evaluated before each iteration.

§body: Vec<(Stmt, bool)>

Loop body statements.

§

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

§expr: Expr

The expression whose value is matched against each case.

§cases: Vec<(Vec<Expr>, Vec<(Stmt, bool)>)>

Each case is a list of match patterns and the body to run on a match.

§otherwise_body: Option<Vec<(Stmt, bool)>>

Fallback body executed when no case matches, or None if there is no otherwise.

§

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

§body: Vec<(Stmt, bool)>

Loop body — always executed at least once before the condition is checked.

§cond: Expr

Condition tested after each iteration; loop exits when it becomes truthy.

§

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

§name: String

The function name (e.g. "fib" in function y = fib(n)).

§outputs: Vec<String>

Output variable names in declaration order.

§params: Vec<String>

Parameter names in declaration order.

§body_source: String

Raw source text of the function body, stored verbatim for re-parsing on each call.

§doc: Option<String>

Documentation extracted from %-prefixed lines immediately before the function keyword.

§

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: Expr

The 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

§try_body: Vec<(Stmt, bool)>

Statements in the protected try block.

§catch_var: Option<String>

Optional name of the catch variable bound to a struct with a message field.

§catch_body: Vec<(Stmt, bool)>

Statements executed when an error is caught.

§

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. 1 or i+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

§name: String

The variable name being modified.

§indices: Vec<Expr>

Index expressions (1 = linear, 2 = row/col).

§value: Expr

The value to write.

§

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.

Trait Implementations§

Source§

impl Debug for Stmt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Stmt

§

impl RefUnwindSafe for Stmt

§

impl Send for Stmt

§

impl Sync for Stmt

§

impl Unpin for Stmt

§

impl UnsafeUnpin for Stmt

§

impl UnwindSafe for Stmt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V