diff --git a/README.md b/README.md index ee975b3..51aa002 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple state machine definition language and interpreter. -A state machine is composed of states - stages of the machine which are run until an exit condition is met and the machine moves to the next stage. State machines in `shakemyleg` are defined as a series of expressions which are run every time the machine runs - the "head". Along with the head is the body - a list of conditions which, when evaluate `true`, run a series of expressions and a `StateOp` (`changeto `, `stay`, `end`). If no condition is true, no action is taken. Conditions are visited in order. +A state machine is composed of states - stages of the machine which are run until an exit condition is met and the machine moves to the next stage. State machines in `shakemyleg` are defined as a series of expressions which are run every time the machine runs - the "head". Along with the head is the body - a list of conditions which, when evaluate `true`, run a series of expressions and a `StateOp` (`changeto `, `stay`, `end`). If no condition is true, no action is taken. Conditions are visited in order. Comments start with a `#`. A very simple example `shakemyleg` machine: ```sml diff --git a/src/compiler.rs b/src/compiler.rs index 32c2f76..e10d3f9 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -154,10 +154,16 @@ pub fn compile(s: &str) -> SML_Result { let mut states = Vec::new(); let mut leading_ws = None; - loop { + let nlines = lines.len(); + while i < nlines { let line = lines[i]; let cstate = c_state_stack.last().unwrap(); + if line.trim_start().starts_with("#") { + i += 1; + continue; + } + if leading_ws.is_none() && matches!(cstate, CompileState::Globals | CompileState::State) { let line_no_ws = line.trim_start(); let ws = line.strip_suffix(line_no_ws).unwrap(); @@ -273,9 +279,6 @@ pub fn compile(s: &str) -> SML_Result { if adv { i += 1; - if i >= lines.len() { - break; - } } }