diff --git a/Cargo.toml b/Cargo.toml index 494728b..78e1485 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] num = "0.4" clap = { version = "3.1.8", features = ["derive"] } +next-gen = "0.1.1" \ No newline at end of file diff --git a/README.md b/README.md index bca4068..d655fe1 100644 --- a/README.md +++ b/README.md @@ -19,22 +19,11 @@ The first build of the program may take some time. ``cargo run --release test-vcd-files/aldec/SPI_Write.vcd`` -## TODO - - [ ] We need a way to merge lines. +# TODO + - [x] We need a way to merge lines. + - [ ] We need to start regression testing the parser over all files + - [ ] Take a look at GTKWave parser to compare effificiency. + - [ ] Send survey to community channel. -### April 14 - - [ ] store timestamps to struct - - [ ] Get file loading status - - [ ] Get all signal scopes - -### April 15 - - [ ] Re-factor to support hooks in the initial file ingest - - [ ] Modularize - -### April 15 - - [ ] Build tree per signal. - - [ ] Each signal also comes with a value change buffer to - avoid frequent disk readouts. - -# VCD Spec Questions -- [ ] I'm pretty sure that only one statement per line is allowed. \ No newline at end of file +### May 18 + - [ ] move while loop into word yielding iterator \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e2e1ef0..624397c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::io::prelude::*; use std::io; use std::fs::File; use std::collections::BTreeMap; +use ::next_gen::prelude::*; use num::*; use clap::Parser; @@ -13,24 +14,6 @@ struct Cli { path: std::path::PathBuf, } -struct Timestamp{ - file_offset: u64, - timestamp: BigInt -} - -struct Cursor{ - line: u64, - col : u64 -} - -enum Tokens { - Date, - End, - String, - Version, - Time, -} - struct Signal { name : String, timeline : BTreeMap, @@ -38,23 +21,21 @@ struct Signal { parent_index : usize } -fn main() -> std::io::Result<()> { - let args = Cli::parse(); - let space = " ".as_bytes()[0]; - let file = File::open(&args.path)?; +#[generator(yield(String))] +fn yield_words(file : File) { let mut reader = io::BufReader::new(file); let mut buffer = String::new(); let mut word_count = 0u64; - let mut do_break = false; + let mut EOF = false; let line_chunk_size = 25; - while {!do_break} { + while {!EOF} { for _ in 0..line_chunk_size { let bytes_read = reader.read_line(&mut buffer).unwrap(); if bytes_read == 0 { - do_break = true; + EOF = true; break } } @@ -62,13 +43,24 @@ fn main() -> std::io::Result<()> { let words = buffer.split_ascii_whitespace(); for word in words { - word_count += 1; + yield_!(word.to_string()); } buffer.clear(); } - dbg!(word_count); +} + +fn main() -> std::io::Result<()> { + let args = Cli::parse(); + + let file = File::open(&args.path)?; + let mut word_count = 0; + mk_gen!(let mut generator = yield_words(file)); + + for word in generator { + word_count += 1; + } Ok(()) }