Skip to content

Commit

Permalink
Use Uncased for Name
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Mar 17, 2024
1 parent 6613769 commit b369fef
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/parser/ast/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Stmt {
} => {
if *temporary {
if let Some(ref db_name) = tbl_name.db_name {
if !"TEMP".eq_ignore_ascii_case(&db_name.0) {
if Uncased::from_borrowed("TEMP") != db_name.0 {
return Err(custom_err!("temporary table name must be unqualified"));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ast/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ impl ToTokens for Id {

impl ToTokens for Name {
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
double_quote(&self.0, s)
double_quote(self.0.as_str(), s)
}
}

Expand Down
17 changes: 6 additions & 11 deletions src/parser/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;

use fmt::{ToTokens, TokenStream};
use indexmap::IndexSet;
use uncased::Uncased;

use crate::custom_err;
use crate::dialect::TokenType::{self, *};
Expand Down Expand Up @@ -989,13 +990,13 @@ impl Id {
// TODO ids (identifier or string)

/// identifier or string or `CROSS` or `FULL` or `INNER` or `LEFT` or `NATURAL` or `OUTER` or `RIGHT`.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Name(pub String); // TODO distinction between Name and "Name"/[Name]/`Name`
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Name(pub Uncased<'static>); // TODO distinction between Name and "Name"/[Name]/`Name`

impl Name {
/// Constructor
pub fn from_token(ty: YYCODETYPE, token: Token) -> Name {
Name(from_token(ty, token))
Name(Uncased::from_owned(from_token(ty, token)))
}
}

Expand Down Expand Up @@ -1115,10 +1116,7 @@ impl ColumnDefinition {
columns: &mut Vec<ColumnDefinition>,
mut cd: ColumnDefinition,
) -> Result<(), ParserError> {
if columns
.iter()
.any(|c| c.col_name.0.eq_ignore_ascii_case(&cd.col_name.0))
{
if columns.iter().any(|c| c.col_name == cd.col_name) {
// TODO unquote
return Err(custom_err!("duplicate column name: {}", cd.col_name));
}
Expand Down Expand Up @@ -1545,10 +1543,7 @@ impl CommonTableExpr {
ctes: &mut Vec<CommonTableExpr>,
cte: CommonTableExpr,
) -> Result<(), ParserError> {
if ctes
.iter()
.any(|c| c.tbl_name.0.eq_ignore_ascii_case(&cte.tbl_name.0))
{
if ctes.iter().any(|c| c.tbl_name == cte.tbl_name) {
return Err(custom_err!("duplicate WITH table name: {}", cte.tbl_name));
}
ctes.push(cte);
Expand Down
5 changes: 3 additions & 2 deletions src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use crate::parser::ast::*;
use crate::parser::{Context, ParserError};
use crate::dialect::{from_token, Token, TokenType};
use log::{debug, error, log_enabled};
use uncased::Uncased;

#[allow(non_camel_case_types)]
type sqlite3ParserError = crate::parser::ParserError;
Expand Down Expand Up @@ -142,15 +143,15 @@ table_option_set(A) ::= table_option(A).
table_option_set(A) ::= table_option_set(X) COMMA table_option(Y). {A = X|Y;}
table_option(A) ::= WITHOUT nm(X). {
let option = X;
if "rowid".eq_ignore_ascii_case(&option.0) {
if Uncased::from_borrowed("rowid") == option.0 {
A = TableOptions::WITHOUT_ROWID;
}else{
return Err(custom_err!("unknown table option: {}", option));
}
}
table_option(A) ::= nm(X). {
let option = X;
if "strict".eq_ignore_ascii_case(&option.0) {
if Uncased::from_borrowed("strict") == option.0 {
A = TableOptions::STRICT;
}else{
return Err(custom_err!("unknown table option: {}", option));
Expand Down

0 comments on commit b369fef

Please sign in to comment.