From 0d144df02197d244a2b45cbb3a4b46563af66d09 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 29 May 2024 14:02:09 +0200 Subject: [PATCH] Revert "refactor: Remove unused GrammarVisitor methods" This reverts commit 645b05f6de01e782b74e6474cd7f385aece57978. --- crates/codegen/runtime/generator/src/parser/grammar.rs | 2 ++ .../src/parser/grammar/precedence_parser_definition.rs | 1 + .../runtime/generator/src/parser/grammar/visitor.rs | 10 +++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/codegen/runtime/generator/src/parser/grammar.rs b/crates/codegen/runtime/generator/src/parser/grammar.rs index c30185e8e6..38e074f88b 100644 --- a/crates/codegen/runtime/generator/src/parser/grammar.rs +++ b/crates/codegen/runtime/generator/src/parser/grammar.rs @@ -30,9 +30,11 @@ pub struct Grammar { impl Grammar { pub fn accept_visitor(&self, visitor: &mut V) { + visitor.grammar_enter(self); for element in self.elements.values() { element.accept_visitor(visitor); } + visitor.grammar_leave(self); } } diff --git a/crates/codegen/runtime/generator/src/parser/grammar/precedence_parser_definition.rs b/crates/codegen/runtime/generator/src/parser/grammar/precedence_parser_definition.rs index 1570183319..4ee572b6d3 100644 --- a/crates/codegen/runtime/generator/src/parser/grammar/precedence_parser_definition.rs +++ b/crates/codegen/runtime/generator/src/parser/grammar/precedence_parser_definition.rs @@ -30,6 +30,7 @@ pub struct PrecedenceParserDefinitionNode { impl Visitable for PrecedenceParserDefinitionNode { fn accept_visitor(&self, visitor: &mut V) { + visitor.precedence_parser_definition_node_enter(self); self.primary_expression.accept_visitor(visitor); } } diff --git a/crates/codegen/runtime/generator/src/parser/grammar/visitor.rs b/crates/codegen/runtime/generator/src/parser/grammar/visitor.rs index b35f407eb7..5256684180 100644 --- a/crates/codegen/runtime/generator/src/parser/grammar/visitor.rs +++ b/crates/codegen/runtime/generator/src/parser/grammar/visitor.rs @@ -1,10 +1,13 @@ use crate::parser::grammar::{ - KeywordScannerDefinitionRef, ParserDefinitionNode, ParserDefinitionRef, - PrecedenceParserDefinitionRef, ScannerDefinitionNode, ScannerDefinitionRef, - TriviaParserDefinitionRef, + Grammar, KeywordScannerDefinitionRef, ParserDefinitionNode, ParserDefinitionRef, + PrecedenceParserDefinitionNode, PrecedenceParserDefinitionRef, ScannerDefinitionNode, + ScannerDefinitionRef, TriviaParserDefinitionRef, }; pub trait GrammarVisitor { + fn grammar_enter(&mut self, _grammar: &Grammar) {} + fn grammar_leave(&mut self, _grammar: &Grammar) {} + fn scanner_definition_enter(&mut self, _scanner: &ScannerDefinitionRef) {} fn keyword_scanner_definition_enter(&mut self, _scanner: &KeywordScannerDefinitionRef) {} fn trivia_parser_definition_enter(&mut self, _trivia_parser: &TriviaParserDefinitionRef) {} @@ -13,6 +16,7 @@ pub trait GrammarVisitor { fn scanner_definition_node_enter(&mut self, _node: &ScannerDefinitionNode) {} fn parser_definition_node_enter(&mut self, _node: &ParserDefinitionNode) {} + fn precedence_parser_definition_node_enter(&mut self, _node: &PrecedenceParserDefinitionNode) {} } pub trait Visitable {