-
-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): implement visitor pattern trait for regex AST
- Loading branch information
Showing
3 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![allow(clippy::print_stdout)] | ||
|
||
use oxc_allocator::Allocator; | ||
use oxc_regular_expression::{ | ||
visit::{RegexAstKind, Visit}, | ||
Parser, ParserOptions, | ||
}; | ||
|
||
struct TestVisitor; | ||
|
||
impl Visit<'_> for TestVisitor { | ||
fn enter_node(&mut self, kind: RegexAstKind) { | ||
println!("enter_node: {kind:?}"); | ||
} | ||
|
||
fn leave_node(&mut self, kind: RegexAstKind) { | ||
println!("leave_node: {kind:?}"); | ||
} | ||
} | ||
|
||
fn main() { | ||
let source_text = r"/(https?:\/\/github\.com\/(([^\s]+)\/([^\s]+))\/([^\s]+\/)?(issues|pull)\/([0-9]+))|(([^\s]+)\/([^\s]+))?#([1-9][0-9]*)($|[\s\:\;\-\(\=])/"; | ||
let allocator = Allocator::default(); | ||
let parser = Parser::new(&allocator, source_text, ParserOptions::default()); | ||
let pattern = parser.parse().unwrap().pattern; | ||
let mut visitor = TestVisitor; | ||
visitor.visit_pattern(&pattern); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.