apache / apache/datafusion-sqlparser-rs
Make Ident enum
- Lingua principale
- Rust
- Stelle
- 3.5k
- Fork
- 772
- Merge medio
- 4g 9h
- PR unite (30g)
- 17
Descrizione
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
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia individuando la struct Ident, la sua implementazione di Display e l’assertion del tokenizer che valida quote_style. Traccia tutti gli utilizzi di Ident.value e quote_style prima di decidere come le varianti dell’enum debbano sostituirli. Il lavoro è completo quando valori di quote_style non validi non possono più raggiungere un panic e il comportamento esistente del parser viene preservato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- compilers
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100