apache / apache/datafusion-sqlparser-rs

Make Ident enum

Abierto
#526 10 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
3.5k
Forks
772
Merge medio
4 d 9 h
PR fusionados (30 d)
17

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza localizando la struct Ident, su implementación de Display y la aserción del tokenizer que valida quote_style. Rastrea todos los usos de Ident.value y quote_style antes de decidir cómo deben reemplazarlos las variantes del enum. La tarea estará terminada cuando los valores de quote_style no válidos ya no puedan provocar un panic y se preserve el comportamiento existente del parser.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust
Área
compilers
Tipo de issue
Refactorización
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.