Skip to content

Commit d89570d

Browse files
committed
token includes span, ident is token
1 parent cdba436 commit d89570d

File tree

9 files changed

+884
-609
lines changed

9 files changed

+884
-609
lines changed

src/ast/ddl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! AST types specific to CREATE/ALTER variants of `SQLStatement`
22
//! (commonly referred to as Data Definition Language, or DDL)
3+
use super::IdentVec;
34
use super::{DataType, Expr, Ident, ObjectName};
45

56
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation

src/ast/mod.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod operator;
1818
mod query;
1919
mod value;
2020

21+
use super::tokenizer::Token;
2122
use std::ops::Deref;
2223

2324
pub use self::data_type::DataType;
@@ -45,7 +46,46 @@ where
4546
}
4647

4748
/// Identifier name, in the originally quoted form (e.g. `"id"`)
48-
pub type Ident = String;
49+
#[derive(Debug, Clone, Eq, Hash)]
50+
pub struct Ident {
51+
pub token: Token,
52+
}
53+
54+
impl PartialEq for Ident {
55+
fn eq(&self, other: &Self) -> bool {
56+
self.to_string() == other.to_string()
57+
}
58+
}
59+
60+
impl PartialEq<String> for Ident {
61+
fn eq(&self, other: &String) -> bool {
62+
&self.to_string() == other
63+
}
64+
}
65+
66+
impl std::fmt::Display for Ident {
67+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68+
f.write_str(&self.token.kind.to_string())
69+
}
70+
}
71+
72+
trait IdentVec {
73+
fn join(&self, sep: &str) -> String;
74+
}
75+
76+
impl IdentVec for Vec<Ident> {
77+
fn join(&self, sep: &str) -> String {
78+
use std::fmt::Write;
79+
let mut res = String::new();
80+
let mut delim = "";
81+
for x in self {
82+
res.push_str(delim);
83+
delim = sep;
84+
write!(&mut res, "{}", x).unwrap();
85+
}
86+
res
87+
}
88+
}
4989

5090
/// An SQL expression of any type.
5191
///

src/ast/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub struct TableAlias {
291291

292292
impl ToString for TableAlias {
293293
fn to_string(&self) -> String {
294-
let mut s = self.name.clone();
294+
let mut s = self.name.to_string();
295295
if !self.columns.is_empty() {
296296
s += &format!(" ({})", comma_separated_string(&self.columns));
297297
}

0 commit comments

Comments
 (0)