-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor html tag peeking #1738
Refactor html tag peeking #1738
Conversation
09f27f2
to
437fac7
Compare
There are a few more problems related to generics that I would like to fix, e.g. |
Replying to your comment here.
Yes! That's exactly why I dislike the current approach. Normal parsing operates on a If you'd like to get your hands dirty a bit I'd love to resolve this mess entirely. |
How about using |
Yes, that's one way to do it, but I think the problem here is a bit bigger because Yew's I think the main problem here is that the tags implement yew/packages/yew-macro/src/html_tree/html_component.rs Lines 59 to 63 in b694865
but we can just replace that with this: if HtmlComponentClose::peek(input.cursor()).is_some() {
let close = input.parse::<HtmlComponentClose>()?;
if close.ty == open.ty {
break;
} else {
// TODO: feel free to improve this error message ex. by including the name of the opening tag.
return Err(syn::Error::new_spanned(close.to_spanned(), "this closing tag doesn't match the corresponding opening tag");
}
} At some point in the future I would still like to get rid of this "speculative" parsing entirely though, but that's not something I want to burden you with. btw, feel free to keep working on it in this pull request unless you want want to get in a fix as soon as possible :P |
I'm not sure I understand. yew/packages/yew-macro/src/html_tree/mod.rs Lines 42 to 73 in b694865
Aren't we basically parsing the html tag twice? (one time peeking and then discarding the result, the second time actually parsing and storing the result) Even though the peek implementation only needs to determine the (This is my first time writing proc macros and I never knew it could be this fun) |
Mostly, yes. To be fair, I don't think we're actually parsing the same thing twice anywhere. The code here is likely the worst offender in this regard. Other implementations of the peek trait are a fair bit better.
We definitely could, the reason we don't is mainly because that makes it much harder to emit good error messages. If you just try one after the other, what do you do when none of them succeed? The easiest way to approach this is to use a little of both worlds. When you have a structure like Yew's implementation of this idea went wrong because of the To give an example: if we only want to distinguish between a normal HTML element The point I'm getting at is that it doesn't make sense to have a For such a trait implementation to be correct in all cases it has no choice but to basically parse the entire thing. |
If I understood correctly, I'll just get rid of all the |
If you want to put in the effort, go for it! |
I created a new method called |
Hmm, how come there is an error with |
I think that failure is a fluke. |
For some reason, |
The diff is a bit messed up now, could you try to fix it @lukechu10? |
Sorry, I am not sure what you mean? |
@lukechu10, there are a few commits in here that really shouldn't be (check the commits). |
You probably want to rebase on top of |
f2f438e
to
af6af1b
Compare
fn path_arguments(cursor: Cursor) -> Option<(PathArguments, Cursor)> { | ||
let (punct, cursor) = cursor.punct()?; | ||
/// Refer to the [`syn::parse::Parse`] implementation for [`AngleBracketedGenericArguments`]. | ||
fn path_arguments(mut cursor: Cursor) -> Option<(PathArguments, Cursor)> { |
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.
Hmm... I still really want to get rid of this and the peek_type
method. Did you run into an issue here?
Other than that this PR is pretty much done, should we just merge this and revisit this topic another time? I don't want to push you to do things you don't really want to do.
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.
The Peek
implementation depends on peek_type
which dependends on path_arguments
. I think it would be best if this were merged first and I'll try to work on removing this in another PR.
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.
alright, sounds like a plan
As of this branch being merged, I can't use html!{
<a class="btn btn-primary" href="https://example.org/">
<svg class="bi" fill="currentColor">
<use href="/bootstrap-icons.svg#wrench"/>
</svg>
<span>{"Go to example.org"}</span>
</a>
} fails with this error:
|
@jbg oh no, could you open a new issue for this? We'll get this fixed ASAP. |
Description
Fixes #1737
Fix for parsing generic component tags with a lowercase type paramater, e.g.
By fixing this, I found another bug related to generic components. The following doesn't work either.
(Note that this is not fixed in this PR)Checklist
cargo make pr-flow