preliminary parser progress
This commit is contained in:
parent
9c4ddffb42
commit
7d1c0e16a8
3 changed files with 85 additions and 13 deletions
59
src/main.rs
59
src/main.rs
|
@ -2,7 +2,8 @@ use std::io::prelude::*;
|
|||
use std::io;
|
||||
use std::fs::File;
|
||||
use std::collections::BTreeMap;
|
||||
use ::next_gen::prelude::*;
|
||||
use chrono::prelude::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
use num::*;
|
||||
use clap::Parser;
|
||||
|
@ -14,16 +15,53 @@ struct Cli {
|
|||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
|
||||
// TODO: implement any timescales greater than a second
|
||||
enum Timescale {ps, ns, us, ms, s}
|
||||
|
||||
struct Metadata {
|
||||
date : DateTime<FixedOffset>,
|
||||
version : String,
|
||||
timescale : Timescale
|
||||
}
|
||||
|
||||
struct Signal {
|
||||
name : String,
|
||||
timeline : BTreeMap<BigInt, BigInt>,
|
||||
children_arena: Vec<usize>,
|
||||
parent_index : usize
|
||||
|
||||
}
|
||||
|
||||
struct SignalAlias {
|
||||
name : String,
|
||||
signal_alias : Rc<Signal>
|
||||
}
|
||||
|
||||
enum SignalGeneric{
|
||||
Signal(Signal),
|
||||
SignalAlias(SignalAlias),
|
||||
}
|
||||
|
||||
struct Scope {
|
||||
name : String,
|
||||
signals : Vec<SignalGeneric>,
|
||||
scopes : Vec<Scope>,
|
||||
}
|
||||
|
||||
struct VCD {
|
||||
metadata : Metadata,
|
||||
top_scopes : Vec<Scope>
|
||||
}
|
||||
|
||||
|
||||
#[generator(yield(&str))]
|
||||
fn yield_words(file : File) {
|
||||
enum VCD_Parser_State {Date, Version, Timescale, SignalTree, Values}
|
||||
enum Date_Parser_State {Date, Day, Month, HHMMSS, Year}
|
||||
|
||||
fn parse_vcd(word: &str, mut state : VCD_Parser_State) {}
|
||||
fn parse_date(word : &str, mut state : Date_Parser_State) {}
|
||||
|
||||
fn yield_word_and_apply(file : File, mut f : impl FnMut(&str)) {
|
||||
let mut reader = io::BufReader::new(file);
|
||||
|
||||
let mut buffer = String::new();
|
||||
|
@ -43,24 +81,23 @@ fn yield_words(file : File) {
|
|||
let words = buffer.split_ascii_whitespace();
|
||||
|
||||
for word in words {
|
||||
yield_!(word);
|
||||
f(word);
|
||||
}
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
// let dt = Utc.datetime_from_str("Fri Nov 28 12:00:09 2014", "%a %b %e %T %Y");
|
||||
|
||||
for word in generator {
|
||||
word_count += 1;
|
||||
}
|
||||
let file = File::open(&args.path)?;
|
||||
let mut word_count = 0;
|
||||
|
||||
yield_word_and_apply(file, |word| {word_count += 1});
|
||||
dbg!(word_count);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Reference in a new issue