From 9b5af034e11d6502246672d5f5fa7972bc23345a Mon Sep 17 00:00:00 2001 From: Ryan Pitasky Date: Sun, 8 Sep 2024 03:23:38 -0400 Subject: [PATCH] data: add None command With a None command, it is easy to delete lines without having to recompute indices. This eases some algorithms. --- ti-basic-optimizer/src/parse/commands/mod.rs | 2 ++ ti-basic-optimizer/src/parse/program.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ti-basic-optimizer/src/parse/commands/mod.rs b/ti-basic-optimizer/src/parse/commands/mod.rs index f93d399..fa9c9d5 100644 --- a/ti-basic-optimizer/src/parse/commands/mod.rs +++ b/ti-basic-optimizer/src/parse/commands/mod.rs @@ -20,6 +20,7 @@ use titokens::{Token, Tokens}; #[derive(Clone, Debug)] pub enum Command { + None, ControlFlow(ControlFlow), Generic(Generic), DelVarChain(DelVarChain), @@ -85,6 +86,7 @@ impl Reconstruct for Command { .chain(target.reconstruct(config)) .collect() }, + Command::None => return vec![], }; Expression::strip_closing_parenthesis(&mut line); diff --git a/ti-basic-optimizer/src/parse/program.rs b/ti-basic-optimizer/src/parse/program.rs index dafe8f0..3504cec 100644 --- a/ti-basic-optimizer/src/parse/program.rs +++ b/ti-basic-optimizer/src/parse/program.rs @@ -90,6 +90,7 @@ impl Program { // to worry about closing strings. self.lines .iter() + .filter(|x|!matches!(x, Command::None)) .map(|line| line.reconstruct(config)) .intersperse(vec![Token::OneByte(0x3F)]) .flatten() @@ -105,7 +106,7 @@ mod tests { #[test] fn parses_newlines_correctly_with_strings() { let mut tokens = load_test_data("/snippets/parsing/strings/newline-stuff.txt"); - let mut program = Program::from_tokens(&mut tokens, &test_tokenizer!()); + let program = Program::from_tokens(&mut tokens, &test_tokenizer!()); assert_eq!(program.lines.len(), 5); } @@ -113,7 +114,7 @@ mod tests { #[test] fn skips_blank_lines() { let mut tokens = load_test_data("/snippets/parsing/ten-blank-lines.txt"); - let mut program = Program::from_tokens(&mut tokens, &test_tokenizer!()); + let program = Program::from_tokens(&mut tokens, &test_tokenizer!()); assert_eq!(program.lines.len(), 0); }