Skip to content

Commit

Permalink
lib.rs uses TokenTree enum, not struct
Browse files Browse the repository at this point in the history
Instead of a `kind` field containting a `TokenNode` variant, a
TokenTree is not an enum with variants of different types. Note that a
TokenTree could be a sequence of TokenTrees. Refs lambda-fairy#121
  • Loading branch information
anxiousmodernman committed Apr 7, 2018
1 parent 3d22f90 commit c4232da
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions maud_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate proc_macro;
mod parse;
mod build;

use proc_macro::{Literal, Span, Term, TokenNode, TokenStream, TokenTree};
use proc_macro::{Literal, Span, Term, TokenStream, TokenTree};
use proc_macro::quote;

type ParseResult<T> = Result<T, String>;
Expand All @@ -27,14 +27,20 @@ pub fn html_debug(input: TokenStream) -> TokenStream {
}

fn expand(input: TokenStream) -> TokenStream {
let output_ident = TokenTree {
kind: TokenNode::Term(Term::intern("__maud_output")),
span: Span::def_site(),
};
//let output_ident = TokenTree {

// kind: TokenNode::Term(Term::intern("__maud_output")),
// // span is a method now, not a field
// span: Span::def_site(),
//};

// A TokenTree is a sequence of TokenTree variants.
let output_ident = TokenTree::Term(Term::new("__maud_output", Span::def_site()));
// Heuristic: the size of the resulting markup tends to correlate with the
// code size of the template itself
let size_hint = input.to_string().len();
let size_hint = TokenNode::Literal(Literal::u64(size_hint as u64));
// QUESTION: u64_suffixed or unsuffixed?
let size_hint = Literal::u64_unsuffixed(size_hint as u64);
let stmts = match parse::parse(input, output_ident.clone()) {
Ok(stmts) => stmts,
Err(e) => panic!(e),
Expand Down

0 comments on commit c4232da

Please sign in to comment.