@@ -46,7 +46,10 @@ use crate::dialect::{
4646} ;
4747use crate :: dialect:: { Dialect , OracleDialect } ;
4848use crate :: keywords:: { Keyword , ALL_KEYWORDS , ALL_KEYWORDS_INDEX } ;
49- use crate :: { ast:: DollarQuotedString , dialect:: HiveDialect } ;
49+ use crate :: {
50+ ast:: { DollarQuotedString , QuoteDelimitedString } ,
51+ dialect:: HiveDialect ,
52+ } ;
5053
5154/// SQL Token enumeration
5255#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -99,11 +102,11 @@ pub enum Token {
99102 /// "National" string literal: i.e: N'string'
100103 NationalStringLiteral ( String ) ,
101104 /// Quote delimited literal. Examples `Q'{ab'c}'`, `Q'|ab'c|'`, `Q'|ab|c|'`
102- /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/19 /sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA)
103- QuoteDelimitedStringLiteral ( char , String , char ) ,
105+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21 /sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA)
106+ QuoteDelimitedStringLiteral ( QuoteDelimitedString ) ,
104107 /// "Nationa" quote delimited literal. Examples `NQ'{ab'c}'`, `NQ'|ab'c|'`, `NQ'|ab|c|'`
105- /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Literals.html)
106- NationalQuoteDelimitedStringLiteral ( char , String , char ) ,
108+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA )
109+ NationalQuoteDelimitedStringLiteral ( QuoteDelimitedString ) ,
107110 /// "escaped" string literal, which are an extension to the SQL standard: i.e: e'first \n second' or E 'first \n second'
108111 EscapedStringLiteral ( String ) ,
109112 /// Unicode string literal: i.e: U&'first \000A second'
@@ -298,10 +301,8 @@ impl fmt::Display for Token {
298301 Token :: TripleDoubleQuotedString ( ref s) => write ! ( f, "\" \" \" {s}\" \" \" " ) ,
299302 Token :: DollarQuotedString ( ref s) => write ! ( f, "{s}" ) ,
300303 Token :: NationalStringLiteral ( ref s) => write ! ( f, "N'{s}'" ) ,
301- Token :: QuoteDelimitedStringLiteral ( q1, ref s, q2) => write ! ( f, "Q'{q1}{s}{q2}'" ) ,
302- Token :: NationalQuoteDelimitedStringLiteral ( q1, ref s, q2) => {
303- write ! ( f, "NQ'{q1}{s}{q2}'" )
304- }
304+ Token :: QuoteDelimitedStringLiteral ( ref s) => s. fmt ( f) ,
305+ Token :: NationalQuoteDelimitedStringLiteral ( ref s) => write ! ( f, "N{s}" ) ,
305306 Token :: EscapedStringLiteral ( ref s) => write ! ( f, "E'{s}'" ) ,
306307 Token :: UnicodeStringLiteral ( ref s) => write ! ( f, "U&'{s}'" ) ,
307308 Token :: HexStringLiteral ( ref s) => write ! ( f, "X'{s}'" ) ,
@@ -2024,9 +2025,9 @@ impl<'a> Tokenizer<'a> {
20242025 }
20252026
20262027 /// Reads a quote delimited string without "backslash escaping" or a word
2027- /// depending on whether `chars.next()` delivers a `'`.
2028+ /// depending on `chars.next()` delivering a `'`.
20282029 ///
2029- /// See <https://docs.oracle.com/en/database/oracle/oracle-database/19 /sqlrf/Literals.html>
2030+ /// See <https://docs.oracle.com/en/database/oracle/oracle-database/21 /sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA >
20302031 fn tokenize_word_or_quote_delimited_string (
20312032 & self ,
20322033 chars : & mut State ,
@@ -2036,14 +2037,14 @@ impl<'a> Tokenizer<'a> {
20362037 // turns an identified quote string literal,
20372038 // ie. `(start-quote-char, string-literal, end-quote-char)`
20382039 // into a token
2039- as_literal : fn ( char , String , char ) -> Token ,
2040+ as_literal : fn ( QuoteDelimitedString ) -> Token ,
20402041 ) -> Result < Token , TokenizerError > {
20412042 match chars. peek ( ) {
20422043 Some ( '\'' ) => {
20432044 chars. next ( ) ;
20442045 // ~ determine the "quote character(s)"
20452046 let error_loc = chars. location ( ) ;
2046- let ( start_quote_char , end_quote_char ) = match chars. next ( ) {
2047+ let ( start_quote , end_quote ) = match chars. next ( ) {
20472048 // ~ "newline" is not allowed by Oracle's SQL Reference,
20482049 // but works with sql*plus nevertheless
20492050 None | Some ( ' ' ) | Some ( '\t' ) | Some ( '\r' ) | Some ( '\n' ) => {
@@ -2067,15 +2068,19 @@ impl<'a> Tokenizer<'a> {
20672068 ) ,
20682069 } ;
20692070 // read the string literal until the "quote character" following a by literal quote
2070- let mut s = String :: new ( ) ;
2071+ let mut value = String :: new ( ) ;
20712072 while let Some ( ch) = chars. next ( ) {
2072- if ch == end_quote_char {
2073+ if ch == end_quote {
20732074 if let Some ( '\'' ) = chars. peek ( ) {
20742075 chars. next ( ) ; // ~ consume the quote
2075- return Ok ( as_literal ( start_quote_char, s, end_quote_char) ) ;
2076+ return Ok ( as_literal ( QuoteDelimitedString {
2077+ start_quote,
2078+ value,
2079+ end_quote,
2080+ } ) ) ;
20762081 }
20772082 }
2078- s . push ( ch) ;
2083+ value . push ( ch) ;
20792084 }
20802085 self . tokenizer_error ( error_loc, "Unterminated string literal" )
20812086 }
0 commit comments