Skip to content

Commit b354fe2

Browse files
committed
report local ambiguity errors earlier
1 parent d704fc9 commit b354fe2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/libsyntax/ext/tt/earley_parser.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
134134
135135
enum parse_result {
136136
success(hashmap<ident, @named_match>),
137-
failure(codemap::span, ~str)
137+
failure(codemap::span, ~str),
138+
error(codemap::span, ~str)
138139
}
139140
140141
fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
141142
ms: ~[matcher]) -> hashmap<ident, @named_match> {
142143
match parse(sess, cfg, rdr, ms) {
143144
success(m) => m,
144-
failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
145+
failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str),
146+
error(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
145147
}
146148
}
147149
@@ -262,7 +264,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
262264
nameize(sess, ms,
263265
vec::map(eof_eis[0u].matches, |dv| dv.pop())));
264266
} else if eof_eis.len() > 1u {
265-
return failure(sp, ~"Ambiguity: multiple successful parses");
267+
return error(sp, ~"Ambiguity: multiple successful parses");
266268
} else {
267269
return failure(sp, ~"Unexpected end of macro invocation");
268270
}
@@ -276,7 +278,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
276278
}
277279
_ => fail
278280
} }), ~" or ");
279-
return failure(sp, fmt!{
281+
return error(sp, fmt!{
280282
"Local ambiguity: multiple parsing options: \
281283
built-in NTs %s or %u other options.",
282284
nts, next_eis.len()});

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import parse::lexer::{new_tt_reader, reader};
66
import parse::token::{FAT_ARROW, SEMI, LBRACE, RBRACE, nt_matchers, nt_tt};
77
import parse::parser::{parser, SOURCE_FILE};
88
import earley_parser::{parse, parse_or_else, success, failure, named_match,
9-
matched_seq, matched_nonterminal};
9+
matched_seq, matched_nonterminal, error};
1010
import std::map::hashmap;
1111

1212
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,
8080
failure(sp, msg) => if sp.lo >= best_fail_spot.lo {
8181
best_fail_spot = sp;
8282
best_fail_msg = msg;
83-
}
83+
},
84+
error(sp, msg) => cx.span_fatal(sp, msg)
8485
}
8586
}
8687
_ => cx.bug(~"non-matcher found in parsed lhses")

0 commit comments

Comments
 (0)