New parser #2

Merged
ThePerfectComputer merged 51 commits from new_parser into main 2022-08-01 21:00:00 +00:00
3 changed files with 39 additions and 67 deletions
Showing only changes of commit 217dea1d41 - Show all commits

View file

@ -27,25 +27,15 @@ The first build of the program may take some time.
You can run all the tests with ``cargo test`` You can run all the tests with ``cargo test``
# TODO # TODO
- [x] We need a way to merge lines. - [ ] support multiple root scopes
- [x] We need to start regression testing the parser over all files
- [x] Decide if I want to return option types
- [x] Propagate all to question mark unwrap types.
- [x] Don't want variation in hh:mm:ss
- [x] parser_atoms -> combinator_atoms
- [x] make parse/types.rs
- [x] remove/replace calls to match_not_empty
- [x] Split ``parse.rs``. It's getting too large.
- [x] move list of files to separate test file/folder
- [ ] support parsing dates with commas - [ ] support parsing dates with commas
- [ ] Fix warning especially usage and restriction warnings once I'm - [ ] Fix warning especially usage and restriction warnings once I'm
able to successfully parse all sample VCDs. able to successfully parse all sample VCDs.
- [ ] Consolidate error messages and add cursors. - [ ] Consolidate error messages and add cursors throughout.
- [ ] Consider what to do with don't care values - [ ] Consider what to do with don't care values
will probably just convert them to strings for now. will probably just convert them to strings for now.
- [ ] Include line and possible column numbers - [ ] Include line and possible column numbers
- [ ] Change states to lowercase
- [ ] Take a look at GTKWave parser to compare effificiency. - [ ] Take a look at GTKWave parser to compare effificiency.
- [ ] Send survey to community channel. - [ ] Send survey to community channel.

View file

@ -187,59 +187,38 @@ fn parse_signal_tree<'a>(
Ok(()) Ok(())
} }
// #[named] // TODO : make this a generic traversal function that applies specified
// fn parse_signal_tree_outer<'a>( // functions upon encountering scopes and signals
// word_reader : &mut WordReader, fn print_signal_tree(
// vcd : &'a mut VCD, root_scope_idx : Scope_Idx,
// signal_map : &mut HashMap<String, Signal_Idx> all_scopes : &Vec<Scope>,
// ) -> Result<(), String> { all_signals : &Vec<Signal>,
// // We assume we've already seen a `$scope` once by the time we reach this function, depth : usize)
// // that why its call `parse_signal_tree_outer` and not just `parse_signal_tree`. {
// // If our WordReader had a `putback` function, we wouldn't need to have a let indent = " ".repeat(depth * 4);
// // `parse_signal_tree_outer`. let Scope_Idx(root_scope_idx) = root_scope_idx;
let root_scope = &all_scopes[root_scope_idx];
let root_scope_name = &root_scope.name;
// // the current scope is the parent scope println!("{indent}scope: {root_scope_name}");
// // $scope module reg_mag_i $end for Signal_Idx(ref signal_idx) in &root_scope.child_signals {
// // ^^^^^^ - module keyword let child_signal = &all_signals[*signal_idx];
// let err = format!("reached end of file without parser leaving {}", function_name!()); let name = match child_signal {
// ident(word_reader, "module")?; Signal::Data{name, ..} => {name}
Signal::Alias{name, ..} => {name}
// // $scope module reg_mag_i $end };
// // ^^^^^^^^^ - scope name println!("{indent} - sig: {name}")
// let (scope_name, _) = word_reader.next_word().ok_or(err)?; }
println!();
// let curr_scope_idx = Scope_Idx(vcd.all_scopes.len());
// // register this scope as a child of the current parent scope
// let Scope_Idx(parent_scope_idx_usize) = parent_scope_idx;
// let parent_scope = vcd.all_scopes.get_mut(parent_scope_idx_usize).unwrap();
// parent_scope.child_scopes.push(curr_scope_idx);
// vcd.all_scopes.push(
// Scope {
// name: scope_name.to_string(),
// parent_idx: parent_scope_idx,
// self_idx: curr_scope_idx,
// child_signals: vec![],
// child_scopes: vec![]
// }
// );
// // $scope module reg_mag_i $end
// // ^^^^ - end keyword
// ident(word_reader, "$end")?;
// // recursive - parse inside of current scope tree
// parse_signal_tree(word_reader, curr_scope_idx, vcd, signal_map);
// // ascend from parsing inside of current scope tree, expect $upscope $end
// ident(word_reader, "$upscope")?;
// ident(word_reader, "$end")?;
// Ok(())
// }
for scope_idx in &root_scope.child_scopes {
// let Scope_Idx(ref scope_idx_usize) = scope_idx;
// let child_scope = &all_scopes[*scope_idx_usize];
print_signal_tree(*scope_idx, all_scopes, all_signals, depth+1);
}
// let root = vcd.all_scopes;
}
pub fn parse_vcd(file : File) -> Result<(), String> { pub fn parse_vcd(file : File) -> Result<(), String> {
let mut word_gen = WordReader::new(file); let mut word_gen = WordReader::new(file);
@ -255,10 +234,12 @@ pub fn parse_vcd(file : File) -> Result<(), String> {
metadata : header, metadata : header,
all_signals: vec![], all_signals: vec![],
all_scopes : vec![], all_scopes : vec![],
scope_roots: vec![],
}; };
parse_signal_tree(&mut word_gen, None, &mut vcd, &mut signal_map)?; parse_signal_tree(&mut word_gen, None, &mut vcd, &mut signal_map)?;
dbg!(&vcd.all_scopes); println!("printing signal tree");
print_signal_tree(Scope_Idx(0), &vcd.all_scopes, &vcd.all_signals, 0);
Ok(()) Ok(())
} }

View file

@ -59,4 +59,5 @@ pub(super) struct Scope {
pub struct VCD { pub struct VCD {
pub(super) metadata : Metadata, pub(super) metadata : Metadata,
pub(super) all_signals : Vec<Signal>, pub(super) all_signals : Vec<Signal>,
pub(super) all_scopes : Vec<Scope>} pub(super) all_scopes : Vec<Scope>,
pub(super) scope_roots : Vec<Scope_Idx>}