use std::collections::HashMap;
use std::env;
use std::path::PathBuf;
use sv_parser::{parse_sv, unwrap_node, Locate, RefNode};
fn main() {
let args: Vec<String> = env::args().collect();
let path = PathBuf::from(&args[1]);
let defines = HashMap::new();
let includes: Vec<PathBuf> = Vec::new();
let result = parse_sv(&path, &defines, &includes, false);
if let Ok((syntax_tree, _)) = result {
for node in &syntax_tree {
match node {
RefNode::ModuleDeclarationNonansi(x) => {
let id = unwrap_node!(x, ModuleIdentifier).unwrap();
let id = get_identifier(id).unwrap();
let id = syntax_tree.get_str(&id).unwrap();
println!("module: {}", id);
}
RefNode::ModuleDeclarationAnsi(x) => {
let id = unwrap_node!(x, ModuleIdentifier).unwrap();
let id = get_identifier(id).unwrap();
let id = syntax_tree.get_str(&id).unwrap();
println!("module: {}", id);
}
_ => (),
}
}
} else {
println!("Parse failed");
}
}
fn get_identifier(node: RefNode) -> Option<Locate> {
match unwrap_node!(node, SimpleIdentifier, EscapedIdentifier) {
Some(RefNode::SimpleIdentifier(x)) => {
return Some(x.nodes.0);
}
Some(RefNode::EscapedIdentifier(x)) => {
return Some(x.nodes.0);
}
_ => None,
}
}