Pass state to instruct

state will store:
- variable positions
master
Raymon Zutekouw 3 years ago
parent c8583af668
commit e23239eb84
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 9
      src/main.rs

@ -16,6 +16,8 @@ use pest::Parser;
#[grammar = "grammars/mblf.pest"] #[grammar = "grammars/mblf.pest"]
struct MblfParser; struct MblfParser;
struct State;
#[derive(StructOpt)] #[derive(StructOpt)]
struct Cli { struct Cli {
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
@ -48,7 +50,7 @@ fn parse_constant(text: &str) -> Result<i32, std::num::ParseIntError> {
} }
} }
fn instruct(statement: Pair<Rule>, out: &mut Builder) { fn instruct(statement: Pair<Rule>, state: &mut State, out: &mut Builder) {
match statement.as_rule() { match statement.as_rule() {
Rule::include => { Rule::include => {
let file_path = extract_operand(statement); let file_path = extract_operand(statement);
@ -143,7 +145,7 @@ fn instruct(statement: Pair<Rule>, out: &mut Builder) {
} }
Rule::loopBlock => { Rule::loopBlock => {
for nested_statement in statement.into_inner() { for nested_statement in statement.into_inner() {
instruct(nested_statement, out); instruct(nested_statement, state, out);
} }
} }
Rule::loopBlockStart => { Rule::loopBlockStart => {
@ -175,8 +177,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.next() .next()
.unwrap(); .unwrap();
let mut state = State;
for statement in parsed_file.into_inner() { for statement in parsed_file.into_inner() {
instruct(statement, &mut builder); instruct(statement, &mut state, &mut builder);
} }
let bf = builder.string().unwrap(); let bf = builder.string().unwrap();

Loading…
Cancel
Save