@@ -9,6 +9,7 @@ import parse::common::*; //resolve bug?
9
9
import parse:: parse_sess;
10
10
import dvec:: { dvec, extensions} ;
11
11
import ast:: { matcher, mtc_tok, mtc_rep, mtc_bb, ident} ;
12
+ import ast_util:: mk_sp;
12
13
import std:: map:: { hashmap, box_str_hash} ;
13
14
14
15
/* This is an Earley-like parser, without support for nonterminals. This
@@ -39,7 +40,8 @@ type matcher_pos = ~{
39
40
sep: option<token>,
40
41
mut idx: uint,
41
42
mut up: matcher_pos_up, // mutable for swapping only
42
- matches: ~[ dvec<@arb_depth>]
43
+ matches: ~[ dvec<@arb_depth>] ,
44
+ sp_lo: uint,
43
45
} ;
44
46
45
47
fn copy_up ( & & mpu: matcher_pos_up ) -> matcher_pos {
@@ -58,13 +60,15 @@ fn count_names(ms: &[matcher]) -> uint {
58
60
} } )
59
61
}
60
62
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 {
62
65
~{ elts: ms, sep: sep, mut idx: 0 u, 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}
64
68
}
65
69
66
70
/* 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 ) }
68
72
69
73
type earley_item = matcher_pos ;
70
74
@@ -88,21 +92,21 @@ fn nameize(&&p_s: parse_sess, ms: ~[matcher], &&res: ~[@arb_depth])
88
92
}
89
93
}
90
94
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) }
92
96
ret ret_val;
93
97
}
94
98
95
99
fn parse( sess: parse_sess, cfg: ast:: crate_cfg, rdr: reader, ms: ~[ matcher] )
96
100
-> hashmap < ident , @arb_depth > {
97
101
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 ) ) ;
99
103
100
104
loop {
101
105
let mut bb_eis = ~[ ] ; // black-box parsed by parser.rs
102
106
let mut next_eis = ~[ ] ; // or proceed normally
103
107
let mut eof_eis = ~[ ] ;
104
108
105
- let { tok: tok , sp: _ } = rdr. peek ( ) ;
109
+ let { tok: tok, sp: sp } = rdr. peek( ) ;
106
110
107
111
/* we append new items to this while we go */
108
112
while cur_eis. len( ) > 0 u { /* for each Earley Item */
@@ -133,7 +137,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
133
137
// doing a lot of array work that will get thrown away
134
138
// most of the time.
135
139
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) ) ) ;
137
142
}
138
143
139
144
new_pos. idx += 1 u;
@@ -176,7 +181,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
176
181
vec:: push( cur_eis, ~{
177
182
elts: matchers, sep: sep, mut idx: 0 u,
178
183
mut up: matcher_pos_up( some( ei_t) ) ,
179
- matches : matches
184
+ matches: matches, sp_lo : sp . lo
180
185
} ) ;
181
186
}
182
187
mtc_bb( _, _, _) { vec:: push( bb_eis, ei) }
0 commit comments