Skip to content

Commit

Permalink
Update Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-fairy committed Dec 31, 2015
1 parent e16aa4c commit 8d0ad20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions maud_macros/src/lib.rs
Expand Up @@ -10,14 +10,17 @@ extern crate maud;
use rustc_plugin::Registry;
use syntax::ast::{Expr, TokenTree};
use syntax::codemap::{DUMMY_SP, Span};
use syntax::errors::FatalError;
use syntax::ext::base::{DummyResult, ExtCtxt, MacEager, MacResult};
use syntax::parse::{token, PResult};
use syntax::parse::token;
use syntax::print::pprust;
use syntax::ptr::P;

mod parse;
mod render;

pub type PResult<T> = Result<T, FatalError>;

fn html(cx: &mut ExtCtxt, sp: Span, mac_name: &str, args: &[TokenTree]) -> PResult<P<Expr>> {
let (write, input) = try!(parse::split_comma(cx, sp, mac_name, args));
parse::parse(cx, sp, write, input)
Expand Down Expand Up @@ -55,7 +58,7 @@ macro_rules! generate_debug_wrappers {
{
match $mac_name(cx, sp, concat!(stringify!($mac_name), "_debug"), args) {
Ok(expr) => {
cx.span_note(sp, &format!("expansion:\n{}",
cx.span_warn(sp, &format!("expansion:\n{}",
pprust::expr_to_string(&expr)));
MacEager::expr(expr)
},
Expand Down
11 changes: 6 additions & 5 deletions maud_macros/src/parse.rs
Expand Up @@ -2,15 +2,16 @@ use std::mem;
use syntax::ast::{Expr, ExprParen, Lit, Stmt, TokenTree};
use syntax::ext::quote::rt::ToTokens;
use syntax::codemap::Span;
use syntax::errors::FatalError;
use syntax::errors::{DiagnosticBuilder, FatalError};
use syntax::ext::base::ExtCtxt;
use syntax::parse::{self, PResult};
use syntax::parse;
use syntax::parse::parser::Parser as RustParser;
use syntax::parse::token::{BinOpToken, DelimToken, IdentStyle, Token};
use syntax::parse::token::keywords::Keyword;
use syntax::ptr::P;

use super::render::Renderer;
use super::PResult;

macro_rules! error {
($cx:expr, $sp:expr, $msg:expr) => ({
Expand Down Expand Up @@ -110,12 +111,12 @@ impl<'cx, 'i> Parser<'cx, 'i> {
}

/// Constructs a Rust AST parser from the given token tree.
fn with_rust_parser<F, T>(&self, tts: Vec<TokenTree>, callback: F) -> T where
F: FnOnce(&mut RustParser<'cx>) -> T
fn with_rust_parser<F, T>(&self, tts: Vec<TokenTree>, callback: F) -> PResult<T> where
F: FnOnce(&mut RustParser<'cx>) -> Result<T, DiagnosticBuilder<'cx>>
{
let mut parser = parse::tts_to_parser(self.render.cx.parse_sess, tts,
self.render.cx.cfg.clone());
let result = callback(&mut parser);
let result = callback(&mut parser).map_err(|mut e| { e.emit(); FatalError });
// Make sure all tokens were consumed
if parser.token != Token::Eof {
let token = parser.this_token_to_string();
Expand Down

0 comments on commit 8d0ad20

Please sign in to comment.