polish: remove warnings on core macero

This commit is contained in:
Jonathan Kelley 2021-09-24 20:51:48 -04:00
parent b43a964f98
commit 6587224deb
10 changed files with 38 additions and 96 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "dioxus-core-macro"
version = "0.1.1"
version = "0.1.2"
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
edition = "2018"
description = "Core macro for Dioxus Virtual DOM"

View file

@ -14,13 +14,12 @@
//!
use {
proc_macro::TokenStream,
proc_macro2::{Span, TokenStream as TokenStream2},
proc_macro2::TokenStream as TokenStream2,
quote::{quote, ToTokens, TokenStreamExt},
syn::{
ext::IdentExt,
parse::{Parse, ParseStream},
token, Error, Expr, ExprClosure, Ident, LitBool, LitStr, Path, Result, Token,
token, Error, Expr, ExprClosure, Ident, LitStr, Result, Token,
},
};
@ -121,7 +120,7 @@ impl ToTokens for ToToksCtx<&Node> {
}
impl Node {
fn peek(s: ParseStream) -> bool {
fn _peek(s: ParseStream) -> bool {
(s.peek(Token![<]) && !s.peek2(Token![/])) || s.peek(token::Brace) || s.peek(LitStr)
}
}

View file

@ -7,44 +7,12 @@ use ::syn::{
};
use proc_macro2::TokenStream;
// #[cfg(not(feature = "verbose-expansions"))]
macro_rules! debug_input {
($expr:expr) => {
$expr
};
}
// #[cfg(not(feature = "verbose-expansions"))]
macro_rules! debug_output {
($expr:expr) => {
$expr
};
}
// #[cfg(feature = "verbose-expansions")]
// macro_rules! debug_input {
// ($expr:expr) => {
// match $expr {
// expr => {
// eprintln!("-------------------\n{} ! ( {} )", FUNCTION_NAME, expr);
// expr
// }
// }
// };
// }
// #[cfg(feature = "verbose-expansions")]
// macro_rules! debug_output {
// ($expr:expr) => {
// match $expr {
// expr => {
// eprintln!("=>\n{}\n-------------------\n", expr);
// expr
// }
// }
// };
// }
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
let IfmtInput {
mut format_literal,

View file

@ -12,10 +12,10 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;
use syn::{
parse::{Parse, ParseStream},
Error, Ident, LitStr, Result, Token,
Error, Ident, Result, Token,
};
pub enum AmbiguousElement<const AS: HTML_OR_RSX> {
pub enum AmbiguousElement<const AS: HtmlOrRsx> {
Element(Element<AS>),
Component(Component<AS>),
}
@ -98,7 +98,7 @@ impl Parse for AmbiguousElement<AS_HTML> {
}
}
impl<const AS: HTML_OR_RSX> ToTokens for AmbiguousElement<AS> {
impl<const AS: HtmlOrRsx> ToTokens for AmbiguousElement<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match self {
AmbiguousElement::Element(el) => el.to_tokens(tokens),

View file

@ -2,12 +2,12 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, ToTokens, TokenStreamExt};
use syn::{
parse::{Parse, ParseStream},
Error, Ident, Result, Token,
Ident, Result, Token,
};
use super::*;
pub struct RsxBody<const AS: HTML_OR_RSX> {
pub struct RsxBody<const AS: HtmlOrRsx> {
custom_context: Option<Ident>,
roots: Vec<BodyNode<AS>>,
}
@ -50,7 +50,7 @@ fn try_parse_custom_context(input: ParseStream) -> Result<Option<Ident>> {
}
/// Serialize the same way, regardless of flavor
impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
impl<const A: HtmlOrRsx> ToTokens for RsxBody<A> {
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
let inner = if self.roots.len() == 1 {
let inner = &self.roots[0];

View file

@ -22,7 +22,7 @@ use syn::{
token, Error, Expr, ExprClosure, Ident, Result, Token,
};
pub struct Component<const AS: HTML_OR_RSX> {
pub struct Component<const AS: HtmlOrRsx> {
// accept any path-like argument
name: syn::Path,
body: Vec<ComponentField<AS>>,
@ -82,13 +82,13 @@ impl Parse for Component<AS_HTML> {
}
}
pub struct BodyParseConfig<const AS: HTML_OR_RSX> {
pub struct BodyParseConfig<const AS: HtmlOrRsx> {
pub allow_fields: bool,
pub allow_children: bool,
pub allow_manual_props: bool,
}
impl<const AS: HTML_OR_RSX> BodyParseConfig<AS> {
impl<const AS: HtmlOrRsx> BodyParseConfig<AS> {
/// The configuration to parse the root
pub fn new_as_body() -> Self {
Self {
@ -214,7 +214,7 @@ impl BodyParseConfig<AS_HTML> {
}
}
impl<const AS: HTML_OR_RSX> ToTokens for Component<AS> {
impl<const AS: HtmlOrRsx> ToTokens for Component<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let name = &self.name;
@ -284,7 +284,7 @@ impl<const AS: HTML_OR_RSX> ToTokens for Component<AS> {
}
// the struct's fields info
pub struct ComponentField<const AS: HTML_OR_RSX> {
pub struct ComponentField<const AS: HtmlOrRsx> {
name: Ident,
content: ContentField,
}
@ -354,7 +354,7 @@ impl Parse for ComponentField<AS_HTML> {
}
}
impl<const AS: HTML_OR_RSX> ToTokens for ComponentField<AS> {
impl<const AS: HtmlOrRsx> ToTokens for ComponentField<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let ComponentField { name, content, .. } = self;
tokens.append_all(quote! {

View file

@ -11,13 +11,13 @@ use syn::{
// =======================================
// Parse the VNode::Element type
// =======================================
pub struct Element<const AS: HTML_OR_RSX> {
pub struct Element<const AS: HtmlOrRsx> {
name: Ident,
key: Option<LitStr>,
attributes: Vec<ElementAttr<AS>>,
listeners: Vec<ElementAttr<AS>>,
children: Vec<BodyNode<AS>>,
is_static: bool,
_is_static: bool,
}
impl Parse for Element<AS_RSX> {
@ -66,31 +66,21 @@ impl Parse for Element<AS_RSX> {
attributes,
children,
listeners,
is_static: false,
_is_static: false,
})
}
}
impl Parse for Element<AS_HTML> {
fn parse(stream: ParseStream) -> Result<Self> {
let l_tok = stream.parse::<Token![<]>()?;
let _l_tok = stream.parse::<Token![<]>()?;
let el_name = Ident::parse(stream)?;
// parse the guts
// let content: ParseBuffer;
// syn::braced!(content in stream);
let mut attributes: Vec<ElementAttr<AS_HTML>> = vec![];
let mut listeners: Vec<ElementAttr<AS_HTML>> = vec![];
let mut children: Vec<BodyNode<AS_HTML>> = vec![];
let mut key = None;
let children: Vec<BodyNode<AS_HTML>> = vec![];
let key = None;
// loop {
// if stream.peek(Token![>]) {
// break;
// } else {
// }
// }
while !stream.peek(Token![>]) {
// self-closing
if stream.peek(Token![/]) {
@ -101,7 +91,7 @@ impl Parse for Element<AS_HTML> {
name: el_name,
key: None,
attributes,
is_static: false,
_is_static: false,
listeners,
children,
});
@ -186,12 +176,12 @@ impl Parse for Element<AS_HTML> {
attributes,
children,
listeners,
is_static: false,
_is_static: false,
})
}
}
impl<const AS: HTML_OR_RSX> ToTokens for Element<AS> {
impl<const AS: HtmlOrRsx> ToTokens for Element<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let name = &self.name;
let attr = &self.attributes;
@ -217,7 +207,7 @@ impl<const AS: HTML_OR_RSX> ToTokens for Element<AS> {
/// =======================================
/// Parse a VElement's Attributes
/// =======================================
struct ElementAttr<const AS: HTML_OR_RSX> {
struct ElementAttr<const AS: HtmlOrRsx> {
element_name: Ident,
name: Ident,
value: AttrType,
@ -346,13 +336,14 @@ fn parse_rsx_element_field(
Ok(())
}
impl<const AS: HTML_OR_RSX> ToTokens for ElementAttr<AS> {
impl<const AS: HtmlOrRsx> ToTokens for ElementAttr<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let el_name = &self.element_name;
let name_str = self.name.to_string();
let nameident = &self.name;
let namespace = match &self.namespace {
// TODO: wire up namespace
let _name_str = self.name.to_string();
let _namespace = match &self.namespace {
Some(t) => quote! { Some(#t) },
None => quote! { None },
};
@ -376,15 +367,3 @@ impl<const AS: HTML_OR_RSX> ToTokens for ElementAttr<AS> {
}
}
}
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
//
// AttrType::BumpText(value) => tokens.append_all(quote! {
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
// }),
// __cx.attr(#name_str, #exp, #namespace, false)
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
// __cx.attr(#name_str, #exp, #namespace, false)
// }),

View file

@ -8,22 +8,18 @@
//! - [ ] Children
//! - [ ] Keys
use super::{AmbiguousElement, HtmlOrRsx, AS_HTML, AS_RSX};
use syn::parse::ParseBuffer;
use super::{AmbiguousElement, AS_HTML, AS_RSX, HTML_OR_RSX};
use {
proc_macro::TokenStream,
proc_macro2::{Span, TokenStream as TokenStream2},
proc_macro2::TokenStream as TokenStream2,
quote::{quote, ToTokens, TokenStreamExt},
syn::{
ext::IdentExt,
parse::{Parse, ParseStream},
token, Error, Expr, ExprClosure, Ident, LitBool, LitStr, Path, Result, Token,
Ident, Result, Token,
},
};
pub struct Fragment<const AS: HTML_OR_RSX> {
pub struct Fragment<const AS: HtmlOrRsx> {
children: Vec<AmbiguousElement<AS>>,
}
@ -67,7 +63,7 @@ impl Parse for Fragment<AS_HTML> {
}
}
impl<const AS: HTML_OR_RSX> ToTokens for Fragment<AS> {
impl<const AS: HtmlOrRsx> ToTokens for Fragment<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let childs = &self.children;
let children = quote! {

View file

@ -26,6 +26,6 @@ pub use element::*;
pub use fragment::*;
pub use node::*;
pub type HTML_OR_RSX = bool;
pub(crate) type HtmlOrRsx = bool;
pub const AS_HTML: bool = true;
pub const AS_RSX: bool = false;

View file

@ -10,7 +10,7 @@ use syn::{
// ==============================================
// Parse any div {} as a VElement
// ==============================================
pub enum BodyNode<const AS: HTML_OR_RSX> {
pub enum BodyNode<const AS: HtmlOrRsx> {
Element(AmbiguousElement<AS>),
Text(TextNode),
RawExpr(Expr),
@ -57,7 +57,7 @@ impl Parse for BodyNode<AS_HTML> {
}
}
impl<const AS: HTML_OR_RSX> ToTokens for BodyNode<AS> {
impl<const AS: HtmlOrRsx> ToTokens for BodyNode<AS> {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match &self {
BodyNode::Element(el) => el.to_tokens(tokens),