Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,12 +1530,13 @@ impl<'a> Tokenizer<'a> {
}
Some('<') => self.consume_for_binop(chars, "<<", Token::ShiftLeft),
Some('-') if self.dialect.supports_geometric_types() => {
chars.next(); // consume
match chars.peek() {
Some('>') => {
self.consume_for_binop(chars, "<->", Token::TwoWayArrow)
}
_ => self.start_binop_opt(chars, "<-", None),
// `<->` is a geometric operator, but `<-123` means `< -123`.
// If the sequence is not `<->`, keep `-` unconsumed so it can be tokenized as a unary minus.
if chars.peekable.clone().nth(1) == Some('>') {
chars.next(); // consume '-'
self.consume_for_binop(chars, "<->", Token::TwoWayArrow)
} else {
self.start_binop(chars, "<", Token::Lt)
}
}
Some('^') if self.dialect.supports_geometric_types() => {
Expand Down Expand Up @@ -2495,7 +2496,8 @@ fn take_char_from_hex_digits(
mod tests {
use super::*;
use crate::dialect::{
BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect, SQLiteDialect,
BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect,
RedshiftSqlDialect, SQLiteDialect,
};
use crate::test_utils::{all_dialects_except, all_dialects_where};
use core::fmt::Debug;
Expand Down Expand Up @@ -4152,4 +4154,40 @@ mod tests {
],
);
}

#[test]
fn tokenize_lt_followed_by_negative_number() {
let sql = "SELECT a <-4000";
let dialect = RedshiftSqlDialect {};
let tokens = Tokenizer::new(&dialect, sql).tokenize().unwrap();
compare(
vec![
Token::make_keyword("SELECT"),
Token::Whitespace(Whitespace::Space),
Token::make_word("a", None),
Token::Whitespace(Whitespace::Space),
Token::Lt,
Token::Minus,
Token::Number("4000".to_string(), false),
],
tokens,
);

// Ensure geometric `<->` is still recognized.
let tokens = Tokenizer::new(&dialect, "SELECT a <-> b")
.tokenize()
Comment on lines +4177 to +4178
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use all_dialects_where(|d| d.supports_geometric_types())? and (I assume) all_dialects() for the case above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aargh, PostgreSQL seems to have issues still with <-4000 case and <=-4000. Seems broken in general. I will see if there is a better solution

.unwrap();
compare(
vec![
Token::make_keyword("SELECT"),
Token::Whitespace(Whitespace::Space),
Token::make_word("a", None),
Token::Whitespace(Whitespace::Space),
Token::TwoWayArrow,
Token::Whitespace(Whitespace::Space),
Token::make_word("b", None),
],
tokens,
);
}
}
Loading