Skip to content

Commit

Permalink
data: add None command
Browse files Browse the repository at this point in the history
With a None command, it is easy to delete lines without having to recompute indices. This eases some algorithms.
  • Loading branch information
rpitasky committed Sep 8, 2024
1 parent 65da33c commit 9b5af03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ti-basic-optimizer/src/parse/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use titokens::{Token, Tokens};

#[derive(Clone, Debug)]
pub enum Command {
None,
ControlFlow(ControlFlow),
Generic(Generic),
DelVarChain(DelVarChain),
Expand Down Expand Up @@ -85,6 +86,7 @@ impl Reconstruct for Command {
.chain(target.reconstruct(config))
.collect()
},
Command::None => return vec![],
};

Expression::strip_closing_parenthesis(&mut line);
Expand Down
5 changes: 3 additions & 2 deletions ti-basic-optimizer/src/parse/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -105,15 +106,15 @@ 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);
}

#[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);
}
Expand Down

0 comments on commit 9b5af03

Please sign in to comment.