Skip to content

Commit

Permalink
Revert "refactor: Remove unused GrammarVisitor methods"
Browse files Browse the repository at this point in the history
This reverts commit 645b05f.
  • Loading branch information
Xanewok committed May 29, 2024
1 parent c935ce6 commit 0d144df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/codegen/runtime/generator/src/parser/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ pub struct Grammar {

impl Grammar {
pub fn accept_visitor<V: GrammarVisitor>(&self, visitor: &mut V) {
visitor.grammar_enter(self);
for element in self.elements.values() {
element.accept_visitor(visitor);
}
visitor.grammar_leave(self);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct PrecedenceParserDefinitionNode {

impl Visitable for PrecedenceParserDefinitionNode {
fn accept_visitor<V: GrammarVisitor>(&self, visitor: &mut V) {
visitor.precedence_parser_definition_node_enter(self);
self.primary_expression.accept_visitor(visitor);
}
}
10 changes: 7 additions & 3 deletions crates/codegen/runtime/generator/src/parser/grammar/visitor.rs
Original file line number Diff line number Diff line change
@@ -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) {}
Expand All @@ -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 {
Expand Down

0 comments on commit 0d144df

Please sign in to comment.