report local ambiguity errors earlier
This commit is contained in:
parent
d704fc9196
commit
b354fe2a91
@ -134,14 +134,16 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
|
||||
|
||||
enum parse_result {
|
||||
success(hashmap<ident, @named_match>),
|
||||
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<ident, @named_match> {
|
||||
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()});
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user