-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Ident enum #526
Comments
@alamb @andygrove @nickolay is this change acceptable? I'd love to have that as well and could work on that if would be reviewed. Maybe I can split the structure from the replacement implementation, so you don't have to review a big PR at once. Otherwise, I'd ask, if possible, to close this :) |
The current design lets users access I guess you could replace the |
I agree with @nickolay -- it isn't clear to me what problem this proposal would solve. Can't users do something like let quote = match ident.quote {
'\'' | '"' | '`' | '[' ==> quote
other => return Err("Unknown quote character: {}, other)
}; Which would safely check for various quote characters and provide an error for unsupported quote styles? |
Actually @alamb I think the main problem is that it's an option, which is a pain to handle. The user would need to unwrap it to be able to match as you showed. But I agree that having an enum to match that would be a pain. If someone wanted the internal value, would need to have the same code for all variants, which doesn't make much sense |
We can have a function on the enum which provide that internal value. pub enum Ident {
Literal(String),
SingleQoute(String),
DoubleQoute(String)
...
}
impl Ident {
fn get_value(&self) -> String {
match self {
return ...
}
}
} and it allows for a client to excessive match all quote style and make sure everything is handled properly. |
Hmmmm I think the idea is OK, but TBH I don't have the need for that, and that doesn't relate to ANSII (I'm aiming to expand the support for ANSII as much as possible here)... @alamb do you think that's reasonable? |
What about something like
yes, I agree this is a potential issue. What about something like the following, which is inline with other parts of the crate: pub struct Ident {
pub value: String,
pub quote_style: QuoteStyle,
}
/// Valid quoting characters
pub enum QuoteStyle {
/// Quote with `'`
SingleQuote,
/// Quote with `"`
DoubleQuote,
...
}
impl Display for QuoteStyle {
...
} |
I worry that changing |
@alamb I think the @omer-shtivi is that enough for you? |
Sounds good I will code it soon
…On Mon, 3 Oct 2022 at 19:20 AugustoFKL ***@***.***> wrote:
@alamb <https://github.com/alamb> I think the QuoteStyle enum is quite
good, and enough. The display of Ident would be adjusted, and maybe some
rebase will be required on downstream projects, but way too less than
adding the variants as proposed by @omer-shtivi
<https://github.com/omer-shtivi>.
@omer-shtivi <https://github.com/omer-shtivi> is that enough for you?
—
Reply to this email directly, view it on GitHub
<#526 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUI7VIV62T3IUOJPA3EHKCDWBMBUHANCNFSM5ZGEBKOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Ident now is a struct with a quote style:
Now it is a bit risky, because if the char isn't the expected it panics:
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:
Now the Display will be:
And we can also implement a method
get_value
:If it is acceptable I will add a PR with the code
The text was updated successfully, but these errors were encountered: