apache / apache/datafusion-sqlparser-rs

Make Ident enum

Aberta
#526 10 comentários 1 reação 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
3.5k
Forks
772
Merge médio
4d 9h
PRs com merge (30d)
17

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Comece localizando a struct Ident, sua implementação de Display e a assertion do tokenizer que valida quote_style. Rastreie todos os usos de Ident.value e quote_style antes de decidir como as variantes do enum devem substituí-los. O trabalho estará concluído quando valores inválidos de quote_style não puderem mais chegar a um panic e o comportamento existente do parser for preservado.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
rust
Domínio
compilers
Tipo de issue
Refatoração
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.