-
Notifications
You must be signed in to change notification settings - Fork 612
Support the string concat operator #178
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ pub enum Token { | |
Div, | ||
/// Modulo Operator `%` | ||
Mod, | ||
/// String concatenation `||` | ||
StringConcat, | ||
/// Left parenthesis `(` | ||
LParen, | ||
/// Right parenthesis `)` | ||
|
@@ -111,6 +113,7 @@ impl fmt::Display for Token { | |
Token::Minus => f.write_str("-"), | ||
Token::Mult => f.write_str("*"), | ||
Token::Div => f.write_str("/"), | ||
Token::StringConcat => f.write_str("||"), | ||
Token::Mod => f.write_str("%"), | ||
Token::LParen => f.write_str("("), | ||
Token::RParen => f.write_str(")"), | ||
|
@@ -374,6 +377,17 @@ impl<'a> Tokenizer<'a> { | |
'+' => self.consume_and_return(chars, Token::Plus), | ||
'*' => self.consume_and_return(chars, Token::Mult), | ||
'%' => self.consume_and_return(chars, Token::Mod), | ||
'|' => { | ||
chars.next(); // consume the '|' | ||
match chars.peek() { | ||
Some('|') => self.consume_and_return(chars, Token::StringConcat), | ||
// a regular '/' operator | ||
_ => Err(TokenizerError(format!( | ||
"Tokenizer Error at Line: {}, Col: {}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reference to '/' is presumably a typo. This should probably say we don't support the single-pipe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made some modifications to the error message. Probably, it would be useful though to support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, another improvement would be to include a simple function which adds line/column information in a consistent way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I see no reason not to.
Agreed. I see you filed #179 about that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes :) |
||
self.line, self.col | ||
))), | ||
} | ||
} | ||
'=' => self.consume_and_return(chars, Token::Eq), | ||
'.' => self.consume_and_return(chars, Token::Period), | ||
'!' => { | ||
|
@@ -562,6 +576,26 @@ mod tests { | |
compare(expected, tokens); | ||
} | ||
|
||
#[test] | ||
fn tokenize_string_string_concat() { | ||
let sql = String::from("SELECT 'a' || 'b'"); | ||
let dialect = GenericDialect {}; | ||
let mut tokenizer = Tokenizer::new(&dialect, &sql); | ||
let tokens = tokenizer.tokenize().unwrap(); | ||
|
||
let expected = vec![ | ||
Token::make_keyword("SELECT"), | ||
Token::Whitespace(Whitespace::Space), | ||
Token::SingleQuotedString(String::from("a")), | ||
Token::Whitespace(Whitespace::Space), | ||
Token::StringConcat, | ||
Token::Whitespace(Whitespace::Space), | ||
Token::SingleQuotedString(String::from("b")), | ||
]; | ||
|
||
compare(expected, tokens); | ||
} | ||
|
||
#[test] | ||
fn tokenize_simple_select() { | ||
let sql = String::from("SELECT * FROM customer WHERE id = 1 LIMIT 5"); | ||
|
Uh oh!
There was an error while loading. Please reload this page.