-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow boolean & update error for byte literals in html!
#3441
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
Merged
ranile
merged 4 commits into
yewstack:master
from
its-the-shrimp:allow-more-literals-in-html
Oct 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b12f4b6
made byte & boolean literals accepted by html
its-the-shrimp 11c1824
improved error message, outruled byte-string to HTML conversion
its-the-shrimp 790f0cc
update tests
its-the-shrimp 558b30c
Merge branch 'master' into allow-more-literals-in-html
its-the-shrimp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| use std::borrow::Cow; | ||
| use std::mem::size_of; | ||
|
|
||
| use proc_macro2::{Span, TokenStream}; | ||
| use quote::{quote_spanned, ToTokens}; | ||
| use syn::spanned::Spanned; | ||
|
|
@@ -75,26 +78,31 @@ impl Stringify for LitStr { | |
| } | ||
| } | ||
| } | ||
|
|
||
| impl Stringify for Lit { | ||
| fn try_into_lit(&self) -> Option<LitStr> { | ||
| let s = match self { | ||
| let mut buf = [0; size_of::<char>()]; | ||
| let s: Cow<'_, str> = match self { | ||
| Lit::Str(v) => return v.try_into_lit(), | ||
| Lit::Char(v) => v.value().to_string(), | ||
| Lit::Int(v) => v.base10_digits().to_string(), | ||
| Lit::Float(v) => v.base10_digits().to_string(), | ||
| Lit::Bool(_) | Lit::ByteStr(_) | Lit::Byte(_) | Lit::Verbatim(_) => return None, | ||
| _ => unreachable!("unknown Lit"), | ||
| Lit::Char(v) => (&*v.value().encode_utf8(&mut buf)).into(), | ||
its-the-shrimp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Lit::Int(v) => v.base10_digits().into(), | ||
| Lit::Float(v) => v.base10_digits().into(), | ||
| Lit::Bool(v) => if v.value() { "true" } else { "false" }.into(), | ||
| Lit::ByteStr(v) => String::from_utf8(v.value()).ok()?.into(), | ||
its-the-shrimp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Lit::Byte(v) => v.value().to_string().into(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is similar to |
||
| Lit::Verbatim(v) => v.to_string().into(), | ||
its-the-shrimp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _ => unreachable!("unknown Lit {:?}", self), | ||
| }; | ||
| Some(LitStr::new(&s, self.span())) | ||
| } | ||
|
|
||
| fn stringify(&self) -> TokenStream { | ||
| self.try_into_lit() | ||
| .as_ref() | ||
| .map(Stringify::stringify) | ||
| .unwrap_or_else(|| stringify_at_runtime(self)) | ||
| .map_or_else(|| stringify_at_runtime(self), Stringify::stringify) | ||
| } | ||
| } | ||
|
|
||
| impl Stringify for Expr { | ||
| fn try_into_lit(&self) -> Option<LitStr> { | ||
| if let Expr::Lit(v) = self { | ||
|
|
@@ -107,7 +115,6 @@ impl Stringify for Expr { | |
| fn stringify(&self) -> TokenStream { | ||
| self.try_into_lit() | ||
| .as_ref() | ||
| .map(Stringify::stringify) | ||
| .unwrap_or_else(|| stringify_at_runtime(self)) | ||
| .map_or_else(|| stringify_at_runtime(self), Stringify::stringify) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.