apache / apache/datafusion-sqlparser-rs
Make Ident enum
- Vorherrschende Sprache
- Rust
- Sterne
- 3.5k
- Forks
- 772
- Ø Merge
- 4 T. 9 Std.
- Gemergte PRs (30 T.)
- 17
Beschreibung
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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne damit, die struct Ident, ihre Display-Implementierung und die Tokenizer-Assertion zu finden, die quote_style validiert. Verfolge alle Verwendungen von Ident.value und quote_style, bevor du entscheidest, wie die Enum-Varianten sie ersetzen sollen. Erledigt ist die Aufgabe, wenn ungültige quote_style-Werte keinen Panic mehr auslösen können und das bestehende Verhalten des Parsers erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust
- Bereich
- compilers
- Issue-Typ
- Refactoring
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100