Show error on unexpected end of input

Without this error, rustc would treat our dummy result as a real one,
causing much pain.
This commit is contained in:
Chris Wong 2015-01-12 16:24:53 +13:00
parent 75dffff135
commit 270781b255
2 changed files with 7 additions and 2 deletions
maud_macros/src

View file

@ -15,7 +15,7 @@ mod parse;
mod render; mod render;
fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> { fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
match parse::parse(cx, args) { match parse::parse(cx, args, sp) {
Some(expr) => MacExpr::new(expr), Some(expr) => MacExpr::new(expr),
None => DummyResult::any(sp), None => DummyResult::any(sp),
} }

View file

@ -35,12 +35,13 @@ macro_rules! ident {
($sp:pat, $x:pat) => (TtToken($sp, token::Ident($x, token::IdentStyle::Plain))) ($sp:pat, $x:pat) => (TtToken($sp, token::Ident($x, token::IdentStyle::Plain)))
} }
pub fn parse(cx: &mut ExtCtxt, input: &[TokenTree]) -> Option<P<Expr>> { pub fn parse(cx: &mut ExtCtxt, input: &[TokenTree], sp: Span) -> Option<P<Expr>> {
let mut success = true; let mut success = true;
let expr = Renderer::with(cx, |render| { let expr = Renderer::with(cx, |render| {
let mut parser = Parser { let mut parser = Parser {
in_attr: false, in_attr: false,
input: input, input: input,
span: sp,
render: render, render: render,
}; };
success = parser.markups(); success = parser.markups();
@ -55,6 +56,7 @@ pub fn parse(cx: &mut ExtCtxt, input: &[TokenTree]) -> Option<P<Expr>> {
struct Parser<'cx: 'r, 's: 'cx, 'i, 'r, 'o: 'r> { struct Parser<'cx: 'r, 's: 'cx, 'i, 'r, 'o: 'r> {
in_attr: bool, in_attr: bool,
input: &'i [TokenTree], input: &'i [TokenTree],
span: Span,
render: &'r mut Renderer<'cx, 's, 'o>, render: &'r mut Renderer<'cx, 's, 'o>,
} }
@ -113,6 +115,8 @@ impl<'cx, 's, 'i, 'r, 'o> Parser<'cx, 's, 'i, 'r, 'o> {
_ => { _ => {
if let [ref tt, ..] = self.input { if let [ref tt, ..] = self.input {
self.render.cx.span_err(tt.get_span(), "invalid syntax"); self.render.cx.span_err(tt.get_span(), "invalid syntax");
} else {
self.render.cx.span_err(self.span, "unexpected end of block");
} }
false false
}, },
@ -179,6 +183,7 @@ impl<'cx, 's, 'i, 'r, 'o> Parser<'cx, 's, 'i, 'r, 'o> {
Parser { Parser {
in_attr: self.in_attr, in_attr: self.in_attr,
input: tts, input: tts,
span: self.span,
render: self.render, render: self.render,
}.markups() }.markups()
} }