Skip to content

Commit

Permalink
Add comments (lines starting with a '#')
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Boyle committed Jul 29, 2024
1 parent 18df839 commit f7557fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <state>`, `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 <state>`, `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
Expand Down
11 changes: 7 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,16 @@ pub fn compile(s: &str) -> SML_Result<StateMachine> {
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();
Expand Down Expand Up @@ -273,9 +279,6 @@ pub fn compile(s: &str) -> SML_Result<StateMachine> {

if adv {
i += 1;
if i >= lines.len() {
break;
}
}
}

Expand Down

0 comments on commit f7557fa

Please sign in to comment.