mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-01 11:47:20 +00:00
TBD fixup multiline comment tokenization
This commit is contained in:
parent
028c613c3f
commit
f958e9d3cf
1 changed files with 27 additions and 11 deletions
|
@ -482,18 +482,19 @@ impl<'a> Tokenizer<'a> {
|
||||||
// TODO: deal with nested comments
|
// TODO: deal with nested comments
|
||||||
loop {
|
loop {
|
||||||
match chars.next() {
|
match chars.next() {
|
||||||
Some(ch) if maybe_closing_comment && ch == '/' => {
|
Some(ch) => {
|
||||||
break Ok(Some(Token::Whitespace(Whitespace::MultiLineComment(s))));
|
if maybe_closing_comment {
|
||||||
|
if ch == '/' {
|
||||||
|
break Ok(Some(Token::Whitespace(Whitespace::MultiLineComment(s))));
|
||||||
|
} else {
|
||||||
|
s.push('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maybe_closing_comment = ch == '*';
|
||||||
|
if !maybe_closing_comment {
|
||||||
|
s.push(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(ch) if maybe_closing_comment && ch != '/' => {
|
|
||||||
maybe_closing_comment = false;
|
|
||||||
s.push('*');
|
|
||||||
s.push(ch);
|
|
||||||
}
|
|
||||||
Some(ch) if !maybe_closing_comment && ch == '*' => {
|
|
||||||
maybe_closing_comment = true;
|
|
||||||
}
|
|
||||||
Some(ch) => s.push(ch),
|
|
||||||
None => {
|
None => {
|
||||||
break Err(TokenizerError(
|
break Err(TokenizerError(
|
||||||
"Unexpected EOF while in a multi-line comment".to_string(),
|
"Unexpected EOF while in a multi-line comment".to_string(),
|
||||||
|
@ -727,6 +728,21 @@ mod tests {
|
||||||
compare(expected, tokens);
|
compare(expected, tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tokenize_multiline_comment_with_even_asterisks() {
|
||||||
|
let sql = String::from("\n/** Comment **/\n");
|
||||||
|
|
||||||
|
let dialect = GenericSqlDialect {};
|
||||||
|
let mut tokenizer = Tokenizer::new(&dialect, &sql);
|
||||||
|
let tokens = tokenizer.tokenize().unwrap();
|
||||||
|
let expected = vec![
|
||||||
|
Token::Whitespace(Whitespace::Newline),
|
||||||
|
Token::Whitespace(Whitespace::MultiLineComment("* Comment *".to_string())),
|
||||||
|
Token::Whitespace(Whitespace::Newline),
|
||||||
|
];
|
||||||
|
compare(expected, tokens);
|
||||||
|
}
|
||||||
|
|
||||||
fn compare(expected: Vec<Token>, actual: Vec<Token>) {
|
fn compare(expected: Vec<Token>, actual: Vec<Token>) {
|
||||||
//println!("------------------------------");
|
//println!("------------------------------");
|
||||||
//println!("tokens = {:?}", actual);
|
//println!("tokens = {:?}", actual);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue