-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new "filter_comment_token" file with 2 filters
- Loading branch information
Wout Feys
committed
Sep 25, 2024
1 parent
95921ca
commit e11b413
Showing
4 changed files
with
44 additions
and
155 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,43 @@ | ||
use sqlparser::tokenizer::{Token, Whitespace}; | ||
|
||
pub fn get_singleline_comments(tokens: Vec<Token>) -> Vec<[String; 2]> { | ||
let singleline_comments: Vec<[String; 2]> = tokens | ||
.iter() | ||
.filter_map(|token| filter_tokens_for_singeline(token)) | ||
.collect(); | ||
|
||
return singleline_comments; | ||
} | ||
|
||
pub fn get_multiline_comments(tokens: Vec<Token>) -> Vec<String> { | ||
let multiline_comments: Vec<String> = tokens | ||
.iter() | ||
.filter_map(|token| filter_tokens_for_multiline(token)) | ||
.collect(); | ||
|
||
return multiline_comments; | ||
} | ||
|
||
fn filter_tokens_for_singeline(token: &Token) -> Option<[String; 2]> { | ||
match token { | ||
Token::Whitespace(whitespace) => { | ||
if let Whitespace::SingleLineComment { comment, prefix } = whitespace { | ||
return Some([comment.clone(), prefix.clone()]); | ||
} | ||
return None; | ||
} | ||
_ => None, | ||
} | ||
} | ||
|
||
fn filter_tokens_for_multiline(token: &Token) -> Option<String> { | ||
match token { | ||
Token::Whitespace(whitespace) => { | ||
if let Whitespace::MultiLineComment(comment) = whitespace { | ||
return Some(comment.clone()); | ||
} | ||
return None; | ||
} | ||
_ => None, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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