-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Implement typed PathPart parsing #96
Implement typed PathPart parsing #96
Conversation
It's also worth mentioning that, assuming a parse with no errors, the first part is always going to be a valid path which we could parse into a |
It might be a good idea to expose/return an |
I would agree, but I wanted to be consistent with |
|
If you're able to do that, please do it (lately, I was working on extracting some changes from @oberblastmeister's more-typed-stuff PR, which involved reducing unnecessary memory allocations, and it would be nice to "keep this spirit", because it might also improve downstream performance, and reduce peak memory usage) |
src/ast/path_util.rs
Outdated
NodeOrToken::Node(node) => { | ||
assert_eq!(node.kind(), NODE_STRING_INTERPOL); | ||
parts.push(PathPart::Interpolation( | ||
ast::StrInterpol::cast(node.clone()).unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cast should mean that the assert directly above it is unnecessary, right?
Reworked based on @oberblastmeister Path changes in 9df0b11. I noticed that commit makes I also combined @zseri I'm going to hold off on changing |
@darichey You can fix that here. What name should we use? |
Sorry, I've been away. I see the rename was done in #134. Is there anything else that needs to be done here? |
@darichey I think |
Sorry, I don't understand. Is this what you mean? node! { #[from(NODE_STRING_CONTENT)] struct StrContent; }
impl StrContent {
tg! { content, TOKEN_STRING_CONTENT }
} enum InterpolPart<T> {
Literal(T)
Interpolation(super::Interpol)
} impl ast::Str {
pub fn parts(&self) -> impl Iterator<Item = InterpolPart<StrContent>> { /* ... */ }
} // name and location tbd
pub fn parse_parts(impl Iterator<Item = InterpolPart<StrContent>>) -> impl Iterator<Item = InterpolPart<String>> { /* ... */ } It's not clear to me what is gained here since we have to examine the contents of the inner Also, how should we apply the same ideas to paths? |
Why do we need the |
|
@darichey @zseri |
Yes. The idea of returning |
Got it, I tried implementing that.
@zseri going way back to this, I just realized that I don't think this is possible for string parts, because we need to iterate over all the children first to calculate the common indent. Do you agree? |
src/ast/path_util.rs
Outdated
} | ||
InterpolPart::Interpolation(interpol) => InterpolPart::Interpolation(interpol), | ||
}) | ||
.collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please omit the .collect()
, what the user intends with the iterator shouldn't be a business of the library, if avoidable. (although I understand if we keep it that way to stay symmetric to ast::Str
, even tho I don't think that's important, because their function is also different)
@darichey |
I think |
yes, correct |
Summary & Motivation
A quick attempt at fixing #95.
Backwards-incompatible changes
PathWithInterpol
is no longer aWrapper
node.Further context
This might not be exactly the direction we want to go, but it seemed the most straightforward. We might consider combining
StrPart
andPathPart
considering their overlap (InterpolationPart
maybe?).