Skip to content
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

Use Uncased for Name #50

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: CI

on: [push, pull_request]

on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
contents: read

Expand All @@ -14,8 +17,8 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build
- name: Run tests
run: cargo test
- uses: actions/checkout@v3
- name: Build
run: cargo build
- name: Run tests
run: cargo test
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
Loading