From b354fe2a918c4821bd66996a023a7bb108bd2862 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 10 Aug 2012 10:46:04 -0700 Subject: [PATCH] report local ambiguity errors earlier --- src/libsyntax/ext/tt/earley_parser.rs | 10 ++++++---- src/libsyntax/ext/tt/macro_rules.rs | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index a0717591b497..7cc9b0e1dc2f 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -134,14 +134,16 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match]) enum parse_result { success(hashmap), - failure(codemap::span, ~str) + failure(codemap::span, ~str), + error(codemap::span, ~str) } fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) -> hashmap { match parse(sess, cfg, rdr, ms) { success(m) => m, - failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str) + failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), + error(sp, str) => sess.span_diagnostic.span_fatal(sp, str) } } @@ -262,7 +264,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) nameize(sess, ms, vec::map(eof_eis[0u].matches, |dv| dv.pop()))); } else if eof_eis.len() > 1u { - return failure(sp, ~"Ambiguity: multiple successful parses"); + return error(sp, ~"Ambiguity: multiple successful parses"); } else { return failure(sp, ~"Unexpected end of macro invocation"); } @@ -276,7 +278,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } _ => fail } }), ~" or "); - return failure(sp, fmt!{ + return error(sp, fmt!{ "Local ambiguity: multiple parsing options: \ built-in NTs %s or %u other options.", nts, next_eis.len()}); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 557b11c5d95a..4a7becf1919f 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -6,7 +6,7 @@ import parse::lexer::{new_tt_reader, reader}; import parse::token::{FAT_ARROW, SEMI, LBRACE, RBRACE, nt_matchers, nt_tt}; import parse::parser::{parser, SOURCE_FILE}; import earley_parser::{parse, parse_or_else, success, failure, named_match, - matched_seq, matched_nonterminal}; + matched_seq, matched_nonterminal, error}; import std::map::hashmap; fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, @@ -80,7 +80,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, failure(sp, msg) => if sp.lo >= best_fail_spot.lo { best_fail_spot = sp; best_fail_msg = msg; - } + }, + error(sp, msg) => cx.span_fatal(sp, msg) } } _ => cx.bug(~"non-matcher found in parsed lhses")