apache / apache/datafusion-sqlparser-rs

Make Ident enum

未关闭
#526 10 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
3.5k
派生
772
平均合并
4 天 9 小时
30 天内合并 PR
17

描述

Ident now is a struct with a quote style:
```
pub struct Ident {
pub value: String,
pub quote_style: Option,
```
Now it is a bit risky, because if the char isn't the expected it panics:
```
assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
```
Now it is true that it shouldn't never get to it, because when we tokenize we are only allowing those to be the quote style, but it is still risk for panics.

I suggest to move Ident to be an enum:
```
pub enum Ident {
Literal(String),
SingleQoute(String),
DoubleQoute(String)
...
}
```
Now the Display will be:
```
impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Literal(value) => write!(f, "{}", value),
SingleQoute(value) => write!(f, "'{}'", value),
...
}
}
```
And we can also implement a method `get_value`:
```
impl Ident {
fn get_value(&self) -> String {
match self {
Literal(value) | SingleQoute(value) ... => return value.clone()
}
}
```

If it is acceptable I will add a PR with the code

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先定位 struct Ident、其 Display 实现,以及用于验证 quote_style 的 tokenizer assertion。在决定应如何用 enum variant 替换它们之前,追踪 Ident.value 和 quote_style 的所有使用位置。完成的标准是:无效的 quote_style 不再可能触发 panic,并且 parser 的现有行为得到保留。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
compilers
Issue 类型
重构
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。