Skip to content

Commit f4fb975

Browse files
committed
Store some span information for stride mismatches errors in MBE TT macros.
1 parent 5342705 commit f4fb975

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/libsyntax/ext/tt/earley_parser.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import parse::common::*; //resolve bug?
99
import parse::parse_sess;
1010
import dvec::{dvec, extensions};
1111
import ast::{matcher, mtc_tok, mtc_rep, mtc_bb, ident};
12+
import ast_util::mk_sp;
1213
import std::map::{hashmap, box_str_hash};
1314

1415
/* This is an Earley-like parser, without support for nonterminals. This
@@ -39,7 +40,8 @@ type matcher_pos = ~{
3940
sep: option<token>,
4041
mut idx: uint,
4142
mut up: matcher_pos_up, // mutable for swapping only
42-
matches: ~[dvec<@arb_depth>]
43+
matches: ~[dvec<@arb_depth>],
44+
sp_lo: uint,
4345
};
4446

4547
fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
@@ -58,13 +60,15 @@ fn count_names(ms: &[matcher]) -> uint {
5860
}})
5961
}
6062

61-
fn new_matcher_pos(ms: ~[matcher], sep: option<token>) -> matcher_pos {
63+
fn new_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint)
64+
-> matcher_pos {
6265
~{elts: ms, sep: sep, mut idx: 0u, mut up: matcher_pos_up(none),
63-
matches: copy vec::from_fn(count_names(ms), |_i| dvec::dvec()) }
66+
matches: copy vec::from_fn(count_names(ms), |_i| dvec::dvec()),
67+
sp_lo: lo}
6468
}
6569

6670
/* logically, an arb_depth should contain only one kind of nonterminal */
67-
enum arb_depth { leaf(whole_nt), seq(~[@arb_depth]) }
71+
enum arb_depth { leaf(whole_nt), seq(~[@arb_depth], codemap::span) }
6872

6973
type earley_item = matcher_pos;
7074

@@ -88,21 +92,21 @@ fn nameize(&&p_s: parse_sess, ms: ~[matcher], &&res: ~[@arb_depth])
8892
}
8993
}
9094
let ret_val = box_str_hash::<@arb_depth>();
91-
for ms.each() |m| { n_rec(p_s, m, res, ret_val) };
95+
for ms.each() |m| { n_rec(p_s, m, res, ret_val) }
9296
ret ret_val;
9397
}
9498

9599
fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
96100
-> hashmap<ident,@arb_depth> {
97101
let mut cur_eis = ~[];
98-
vec::push(cur_eis, new_matcher_pos(ms, none));
102+
vec::push(cur_eis, new_matcher_pos(ms, none, rdr.peek().sp.lo));
99103

100104
loop {
101105
let mut bb_eis = ~[]; // black-box parsed by parser.rs
102106
let mut next_eis = ~[]; // or proceed normally
103107
let mut eof_eis = ~[];
104108

105-
let {tok: tok, sp: _} = rdr.peek();
109+
let {tok: tok, sp: sp} = rdr.peek();
106110

107111
/* we append new items to this while we go */
108112
while cur_eis.len() > 0u { /* for each Earley Item */
@@ -133,7 +137,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
133137
// doing a lot of array work that will get thrown away
134138
// most of the time.
135139
for ei.matches.eachi() |idx, elt| {
136-
new_pos.matches[idx].push(@seq(elt.get()));
140+
new_pos.matches[idx]
141+
.push(@seq(elt.get(), mk_sp(ei.sp_lo,sp.hi)));
137142
}
138143

139144
new_pos.idx += 1u;
@@ -176,7 +181,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
176181
vec::push(cur_eis, ~{
177182
elts: matchers, sep: sep, mut idx: 0u,
178183
mut up: matcher_pos_up(some(ei_t)),
179-
matches: matches
184+
matches: matches, sp_lo: sp.lo
180185
});
181186
}
182187
mtc_bb(_,_,_) { vec::push(bb_eis, ei) }

0 commit comments

Comments
 (0)