-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add SPPF Visitor #96
base: master
Are you sure you want to change the base?
WIP: Add SPPF Visitor #96
Conversation
…999-personal/hime into patch-sppf-visitor-gen
Seems like there is a bit of a trouble on the cloning part. I'm not sure why the visitors are not following...
#[derive(Clone, Debug)]
struct ASTWalker {
test: VectorSync<&'static str>
}
impl c::AstVisitor for ASTWalker {
fn on_variable_declaration(&mut self, node: &AstNode) {
self.test = self.test.push_back("declaration");
println!("{:?}", self);
}
fn on_variable_expression(&mut self, node: &AstNode) {
self.test = self.test.push_back("expression");
println!("{:?}", self);
}
fn on_variable_block_item(&mut self, node: &AstNode) {
self.test = self.test.push_back("block_item");
println!("{:?}", self);
}
fn on_variable_compound_statement(&mut self, node: &AstNode) {
self.test = self.test.push_back("compound_statement");
println!("{:?}", self);
}
fn on_variable_block_item_list(&mut self, node: &AstNode) {
self.test = self.test.push_back("block_item_list");
println!("{:?}", self);
}
fn on_variable_function_definition(&mut self, node: &AstNode) {
self.test = self.test.push_back("function_definition");
println!("{:?}", self);
}
fn on_variable_statement(&mut self, node: &AstNode) {
self.test = self.test.push_back("statement");
println!("{:?}", self);
}
fn on_variable_expression_statement(&mut self, node: &AstNode) {
self.test = self.test.push_back("expression_statement");
println!("{:?}", self);
}
fn on_variable_jump_statement(&mut self, _node: &AstNode) {
self.test = self.test.push_back("jump_statement");
println!("{:?}", self);
}
}
impl c::SppfVisitor for ASTWalker {
fn on_variable_declaration(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("declaration");
println!("{:?}", self);
}
fn on_variable_expression(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("expression");
println!("{:?}", self);
}
fn on_variable_block_item(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("block_item");
println!("{:?}", self);
}
fn on_variable_compound_statement(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("compound_statement");
println!("{:?}", self);
}
fn on_variable_block_item_list(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("block_item_list");
println!("{:?}", self);
}
fn on_variable_function_definition(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("function_definition");
println!("{:?}", self);
}
fn on_variable_statement(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("statement");
println!("{:?}", self);
}
fn on_variable_expression_statement(&mut self, node: &SppfNodeVersion) {
self.test = self.test.push_back("expression_statement");
println!("{:?}", self);
}
fn on_variable_jump_statement(&mut self, _node: &SppfNodeVersion) {
self.test = self.test.push_back("jump_statement");
println!("{:?}", self);
}
}
fn main() {
let result = c::parse_str_to_sppf(
r#"
int main() {
T * a;
U * b;
return a * b;
}
"#);
let mut walker: Box<dyn SppfVisitor> = Box::new(ASTWalker { test: Vector::new_sync() });
c::visit_sppf(&result, &mut walker);
} I'm using the C grammar here: #88 (comment) I'm also using rpds for VectorSync (a persistent data structure that supports O(1) clone) |
Seems like the backlink to the next AST node on divergent version was not present. I also find it curious that I can get an expected result using the optimized grammar here: #88 (comment)
|
This PR implements part of the idea expressed here: #88 (comment)
TODO: