Skip to content

Commit ff3bc6e

Browse files
committed
Make the parser tree mutable for visitor.
Signed-off-by: James Goppert <james.goppert@gmail.com>
1 parent b19d934 commit ff3bc6e

File tree

6 files changed

+207
-438
lines changed

6 files changed

+207
-438
lines changed

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ extern crate macro_rules_attribute;
88
pub use s1_parser::ast;
99
pub use s2_analysis::parser_helper::parse_file;
1010
pub use s2_analysis::print_visitor::PrintVisitor;
11-
pub use s2_analysis::visitor::{Visitable, Visitor};
11+
pub use s2_analysis::visitable::Visitable;
12+
pub use s2_analysis::visitor::Visitor;

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Args {
1515

1616
fn main() -> Result<(), Box<dyn std::error::Error>> {
1717
let args = Args::parse();
18-
let def = rumoca_parser::parse_file(&args.model_file);
18+
let mut def = rumoca_parser::parse_file(&args.model_file);
1919

2020
if args.verbose {
2121
println!("{:#?}", def);

src/s2_analysis/print_visitor.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Default for PrintVisitor {
2121
}
2222
}
2323

24-
impl<'a> Visitor<'a> for PrintVisitor {
24+
impl Visitor for PrintVisitor {
2525
fn enter_any(&mut self) {
2626
self.level += 1;
2727
}
@@ -30,21 +30,21 @@ impl<'a> Visitor<'a> for PrintVisitor {
3030
self.level -= 1;
3131
}
3232

33-
fn enter_stored_definition(&mut self, _def: &'a ast::StoredDefinition) {
33+
fn enter_stored_definition(&mut self, _def: &mut ast::StoredDefinition) {
3434
self.print("Stored Definition");
3535
}
3636

37-
fn enter_class_definition(&mut self, def: &'a ast::ClassDefinition) {
37+
fn enter_class_definition(&mut self, def: &mut ast::ClassDefinition) {
3838
if let ast::ClassSpecifier::Long { name, .. } = &def.specifier {
3939
self.print(&format!("class {}", name));
4040
}
4141
}
4242

43-
fn exit_class_definition(&mut self, _def: &'a ast::ClassDefinition) {
43+
fn exit_class_definition(&mut self, _def: &mut ast::ClassDefinition) {
4444
println!("\n");
4545
}
4646

47-
fn enter_expression(&mut self, def: &'a ast::Expression) {
47+
fn enter_expression(&mut self, def: &mut ast::Expression) {
4848
match def {
4949
ast::Expression::Binary { op, .. } => {
5050
self.print(&format!("{:?}", op));
@@ -79,7 +79,7 @@ impl<'a> Visitor<'a> for PrintVisitor {
7979
}
8080
}
8181

82-
fn enter_equation(&mut self, def: &'a ast::Equation) {
82+
fn enter_equation(&mut self, def: &mut ast::Equation) {
8383
match def {
8484
ast::Equation::Connect { .. } => {
8585
self.print("connect");
@@ -94,11 +94,11 @@ impl<'a> Visitor<'a> for PrintVisitor {
9494
}
9595
}
9696

97-
fn exit_component_declaration(&mut self, def: &'a ast::ComponentDeclaration) {
97+
fn enter_component_declaration(&mut self, def: &mut ast::ComponentDeclaration) {
9898
self.print(&format!("component: {}", def.declaration.name));
9999
}
100100

101-
fn exit_component_reference(&mut self, def: &'a ast::ComponentReference) {
101+
fn exit_component_reference(&mut self, def: &mut ast::ComponentReference) {
102102
let mut s: String = "".to_string();
103103
for (index, part) in def.parts.iter().enumerate() {
104104
if index != 0 || def.local {

0 commit comments

Comments
 (0)