cleaner types
This commit is contained in:
parent
2a2eb8669b
commit
d22418cf2b
29
src/main.rs
29
src/main.rs
|
@ -26,15 +26,12 @@ struct Scope_Idx(usize);
|
||||||
struct Signal_Idx(usize);
|
struct Signal_Idx(usize);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Date {No_Date, Date(DateTime<Utc>)}
|
struct Version(String);
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum Version {No_Version, Version(String)}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Metadata {
|
struct Metadata {
|
||||||
date : Date,
|
date : Option<DateTime<Utc>>,
|
||||||
version : Version,
|
version : Option<Version>,
|
||||||
timescale : Timescale}
|
timescale : Timescale}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -62,15 +59,18 @@ struct VCD {
|
||||||
// the root scope should always be placed at index 0
|
// the root scope should always be placed at index 0
|
||||||
all_scopes : Vec<Scope>}
|
all_scopes : Vec<Scope>}
|
||||||
|
|
||||||
|
// TODO : Date_PArser_State -> Parse_Date
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Date_Parser_State {Weekday, Month, Day, HHMMSS, Year, End}
|
enum Date_Parser_State {Weekday, Month, Day, HHMMSS, Year, End}
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Version_Parser_State {Parsing, Done}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum VCD_Parser_State {
|
enum VCD_Parser_State {
|
||||||
Begin,
|
Begin,
|
||||||
Date(Date_Parser_State),
|
Date(Date_Parser_State),
|
||||||
Parse_Version,
|
Parse_Version(Version_Parser_State),
|
||||||
Parse_Signal_Tree,
|
Parse_Signal_Tree,
|
||||||
Parse_Signal_Values}
|
Parse_Signal_Values}
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ impl VCD {
|
||||||
.datetime_from_str("Thu Jan 1 00:00:00 1970", "%a %b %e %T %Y")
|
.datetime_from_str("Thu Jan 1 00:00:00 1970", "%a %b %e %T %Y")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let metadata = Metadata {
|
let metadata = Metadata {
|
||||||
date : Date::No_Date,
|
date : None,
|
||||||
version : Version::No_Version,
|
version : None,
|
||||||
timescale : Timescale::unit};
|
timescale : Timescale::unit};
|
||||||
let signal = Vec::<SignalGeneric>::new();
|
let signal = Vec::<SignalGeneric>::new();
|
||||||
VCD {
|
VCD {
|
||||||
|
@ -135,6 +135,7 @@ impl<'a> VCD_Parser<'a> {
|
||||||
_ => Err(format!("unsure what to do with {word:?} in state `{state:?}`"))
|
_ => Err(format!("unsure what to do with {word:?} in state `{state:?}`"))
|
||||||
}
|
}
|
||||||
VCD_Parser_State::Date(_) => self.parse_date(word),
|
VCD_Parser_State::Date(_) => self.parse_date(word),
|
||||||
|
VCD_Parser_State::Parse_Version(_) => self.parse_date(word),
|
||||||
// TODO : Enable the following in production
|
// TODO : Enable the following in production
|
||||||
// _ => Err(format!("parser in bad state : {state:?}"))TODO : Disable the following in production
|
// _ => Err(format!("parser in bad state : {state:?}"))TODO : Disable the following in production
|
||||||
// TODO : Disable the following in production
|
// TODO : Disable the following in production
|
||||||
|
@ -185,7 +186,7 @@ impl<'a> VCD_Parser<'a> {
|
||||||
let dt = Utc.datetime_from_str(date, "%a %b %e %T %Y")
|
let dt = Utc.datetime_from_str(date, "%a %b %e %T %Y")
|
||||||
.expect(&format!("invalid date {date}")[..]);
|
.expect(&format!("invalid date {date}")[..]);
|
||||||
|
|
||||||
self.vcd.metadata.date = Date::Date(dt);
|
self.vcd.metadata.date = Some(dt);
|
||||||
|
|
||||||
*state = VCD_Parser_State::Date(Date_Parser_State::End);
|
*state = VCD_Parser_State::Date(Date_Parser_State::End);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -194,7 +195,10 @@ impl<'a> VCD_Parser<'a> {
|
||||||
{
|
{
|
||||||
let expected_word = "$end";
|
let expected_word = "$end";
|
||||||
match word {
|
match word {
|
||||||
expected_word => {*state = VCD_Parser_State::Parse_Version; Ok(())}
|
expected_word => {
|
||||||
|
*state = VCD_Parser_State::Parse_Version(Version_Parser_State::Parsing);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
_ => Err(format!("expected `{expected_word}` but found `{word}`"))
|
_ => Err(format!("expected `{expected_word}` but found `{word}`"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,9 +207,6 @@ impl<'a> VCD_Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn advance_VCD_parser_FSM(word: &str, mut state : VCD_Parser_State) {}
|
|
||||||
fn advance_Date_parser_FSM(word : &str, mut state : Date_Parser_State) {}
|
|
||||||
|
|
||||||
fn yield_word_and_apply(file : File, mut f : impl FnMut(&str) -> Result<(), String>) {
|
fn yield_word_and_apply(file : File, mut f : impl FnMut(&str) -> Result<(), String>) {
|
||||||
let mut reader = io::BufReader::new(file);
|
let mut reader = io::BufReader::new(file);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue