-
Notifications
You must be signed in to change notification settings - Fork 605
Require space after -- to start single line comment in MySQL #1705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/dialect/mod.rs
Outdated
/// Otherwise it's interpreted as a double minus operator | ||
/// | ||
/// MySQL: <https://dev.mysql.com/doc/refman/8.4/en/ansi-diff-comments.html> | ||
fn requires_whitespace_to_start_comment(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn requires_whitespace_to_start_comment(&self) -> bool { | |
fn requires_single_line_comment_whitespace(&self) -> bool { |
thinking something like this to flag that this is only for the --
comment style
src/dialect/mod.rs
Outdated
@@ -880,6 +880,15 @@ pub trait Dialect: Debug + Any { | |||
fn supports_table_hints(&self) -> bool { | |||
false | |||
} | |||
|
|||
/// Returns whether it's the start of a single line comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns whether it's the start of a single line comment | |
/// Returns true if this dialect requires a whitespace after `--` for single line comments. |
src/dialect/mysql.rs
Outdated
/// Returns whether it's the start of a single line comment | ||
/// e.g. MySQL requires a space after `--` to be a single line comment | ||
/// Otherwise it's interpreted as a double minus operator | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already duplicated at the definition of the dialect method, we could consider not including it (The link to the doc on the other hand is useful in any case)
src/tokenizer.rs
Outdated
// MySQL requires a space after the -- for a single-line comment | ||
// Otherwise it's interpreted as two minus signs | ||
// e.g. UPDATE account SET balance=balance--1 | ||
// WHERE account_id=5752; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the example to the doc string in the dialect method? That would help clarify the behavior to folks without having to dig deeper in the docs or the parser code.
Then for the rest of the comment here we can probably skip since we've already documented as much in the dialect method
src/tokenizer.rs
Outdated
match chars.peekable.clone().nth(1) { | ||
Some(' ') => (), | ||
_ => is_comment = false, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match chars.peekable.clone().nth(1) { | |
Some(' ') => (), | |
_ => is_comment = false, | |
} | |
is_comment = Some(' ') == chars.peekable.clone().nth(1); |
looks like this can be simplified?
src/tokenizer.rs
Outdated
Some('-') => { | ||
chars.next(); // consume the second '-', starting a single-line comment | ||
|
||
if let Some('-') = chars.peek() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to have this remain as a match statement, calling chars.peek()
only once? i.e.
match chars.peek() {
Some('-') => { ... }
Some('>') => { ... }
}
tests/sqlparser_mysql.rs
Outdated
match mysql().parse_sql_statements( | ||
r#" | ||
UPDATE account SET balance=balance--1 | ||
WHERE account_id=5752 | ||
"#, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use mysql().verified_stmt()
for the tests?
@iffyio Addressed all your comments, great feedback. |
@iffyio doing a check for which characters are allowed to start comment (using a script against mysql) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not super clear which characters belong to
my_iscntrl
andmy_isspace
but we cannot usechar.is_whitespace()
as it includes'\n'
?