You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
#![feature(proc_macro_diagnostic)]
|
|
#![feature(proc_macro_span)]
|
|
|
|
use proc_macro::{Delimiter, Group, Punct, Spacing, TokenStream, TokenTree};
|
|
use std::str::FromStr;
|
|
|
|
pub(crate) trait TtIter: Iterator<Item = TokenTree> {}
|
|
impl<T> TtIter for T where T: Iterator<Item = TokenTree> {}
|
|
|
|
mod compiler;
|
|
mod parser;
|
|
|
|
use parser::Parser;
|
|
|
|
/// Build a view tree out of a template written in the uwui DSL.
|
|
#[proc_macro]
|
|
pub fn template(input: TokenStream) -> TokenStream {
|
|
let mut stream = input.into_iter().peekable();
|
|
let parser = Parser::from(&mut stream);
|
|
let array = TokenTree::Group(Group::new(
|
|
Delimiter::Bracket,
|
|
TokenStream::from_iter(parser.flat_map(|component| {
|
|
component
|
|
.compile()
|
|
.chain([Punct::new(',', Spacing::Alone).into()])
|
|
})),
|
|
));
|
|
|
|
let mut output = TokenStream::from_str("::std::vec::Vec::<_>::from").unwrap();
|
|
output.extend(TokenStream::from(TokenTree::Group(Group::new(
|
|
Delimiter::Parenthesis,
|
|
array.into(),
|
|
))));
|
|
output = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Brace, output)));
|
|
output
|
|
}
|