aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2019-10-06 21:42:52 +0200
committerReiner Herrmann <reiner@reiner-h.de>2019-10-06 21:42:52 +0200
commitc984c588095b8f73264e297090ef642183df6510 (patch)
tree89204a28195a509462498665371ca8569c816982 /src
parent9f55cf9ad7e7a07bc422cd3e5dd41a8c8ca4c189 (diff)
Add a few comments
Diffstat (limited to 'src')
-rw-r--r--src/main.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 66319b1..d147a40 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -72,6 +72,7 @@ impl Program {
}
}
+/// read the program from the specified file into a string
fn read_program(filename: &str) -> Result<String, io::Error> {
let file = File::open(filename)?;
let mut content = String::new();
@@ -80,6 +81,7 @@ fn read_program(filename: &str) -> Result<String, io::Error> {
Ok(content)
}
+/// update loop tokens and look for the matching opposing parts
fn find_loops(commands: &mut Vec<Command>) -> Result<(), String> {
let mut loop_starts = Vec::new();
for i in 0 .. commands.len() {
@@ -151,11 +153,13 @@ fn optimize(program: &mut Vec<Command>) {
optimize_sequences(program);
}
+/// filter out all non-syntax characters from the input
fn preprocess(program: &str) -> String {
let allowed_chars = ['>', '<', '+', '-', '.', ',', '[', ']'];
program.chars().filter(|c| allowed_chars.contains(c)).collect()
}
+/// convert input string into syntax tokens
fn tokenize(input: &str) -> Vec<Command> {
input.chars().map(|token|
match token {