@@ -27,7 +27,7 @@ type tt_frame = @{
27
27
up : tt_frame_up
28
28
} ;
29
29
30
- type tt_reader = @ {
30
+ type tt_reader = ~ {
31
31
span_diagnostic : diagnostic:: span_handler ,
32
32
interner : @interner:: interner < @str > ,
33
33
mut cur : tt_frame ,
@@ -39,28 +39,29 @@ type tt_reader = @{
39
39
fn new_tt_reader ( span_diagnostic : diagnostic:: span_handler ,
40
40
itr : @interner:: interner < @str > , src : [ ast:: token_tree ] )
41
41
-> tt_reader {
42
- let r = @ { span_diagnostic: span_diagnostic, interner: itr,
42
+ let r = ~ { span_diagnostic: span_diagnostic, interner: itr,
43
43
mut cur : @{ readme : src, mut idx : 0 u,
44
44
up : tt_frame_up ( option:: none) } ,
45
45
mut cur_tok: token:: EOF , /* dummy value, never read */
46
46
mut cur_chpos: 0 u /* dummy value, never read */
47
47
} ;
48
- ( r as reader ) . next_token ( ) ; /* get cur_tok and cur_chpos set up */
48
+ //tt_next_token(r ); /* get cur_tok and cur_chpos set up */
49
49
ret r;
50
50
}
51
51
52
52
pure fn dup_tt_frame ( & & f: tt_frame ) -> tt_frame {
53
53
@{ readme: f. readme , mut idx: f. idx ,
54
54
up: alt f. up {
55
- tt_frame_up ( o_f ) {
56
- tt_frame_up ( option :: map ( o_f , dup_tt_frame) )
55
+ tt_frame_up ( some ( up_frame ) ) {
56
+ tt_frame_up ( some ( dup_tt_frame ( up_frame ) ) )
57
57
}
58
+ tt_frame_up ( none) { tt_frame_up ( none) }
58
59
}
59
60
}
60
61
}
61
62
62
63
pure fn dup_tt_reader ( & & r: tt_reader ) -> tt_reader {
63
- @ { span_diagnostic: r. span_diagnostic , interner: r. interner ,
64
+ ~ { span_diagnostic: r. span_diagnostic , interner: r. interner ,
64
65
mut cur: dup_tt_frame ( r. cur ) ,
65
66
mut cur_tok: r. cur_tok , mut cur_chpos: r. cur_chpos }
66
67
}
@@ -114,38 +115,13 @@ impl string_reader_as_reader of reader for string_reader {
114
115
impl tt_reader_as_reader of reader for tt_reader {
115
116
fn is_eof ( ) -> bool { self . cur_tok == token:: EOF }
116
117
fn next_token ( ) -> { tok : token:: token , chpos : uint } {
117
- let ret_val = { tok: self . cur_tok , chpos: self . cur_chpos } ;
118
- if self . cur . idx >= vec:: len ( self . cur . readme ) {
119
- /* done with this set; pop */
120
- alt self . cur . up {
121
- tt_frame_up ( option:: none) {
122
- self . cur_tok = token:: EOF ;
123
- ret ret_val;
124
- }
125
- tt_frame_up ( option:: some ( tt_f) ) {
126
- self . cur = tt_f;
127
- /* the above `if` would need to be a `while` if we didn't know
128
- that the last thing in a `tt_delim` is always a `tt_flat` */
129
- self . cur . idx += 1 u;
130
- }
131
- }
132
- }
133
- /* if `tt_delim`s could be 0-length, we'd need to be able to switch
134
- between popping and pushing until we got to an actual `tt_flat` */
135
- loop { /* because it's easiest, this handles `tt_delim` not starting
136
- with a `tt_flat`, even though it won't happen */
137
- alt self . cur . readme [ self . cur . idx ] {
138
- tt_delim ( tts) {
139
- self . cur = @{ readme: tts, mut idx: 0 u,
140
- up: tt_frame_up ( option:: some ( self . cur ) ) } ;
141
- }
142
- tt_flat ( chpos, tok) {
143
- self . cur_chpos = chpos; self . cur_tok = tok;
144
- self . cur . idx += 1 u;
145
- ret ret_val;
146
- }
147
- }
118
+ /* weird resolve bug: if the following `if`, or any of its
119
+ statements are removed, we get resolution errors */
120
+ if false {
121
+ let _ignore_me = 0 ;
122
+ let _me_too = self . cur . readme [ self . cur . idx ] ;
148
123
}
124
+ tt_next_token ( self )
149
125
}
150
126
fn fatal ( m : str ) -> ! {
151
127
self . span_diagnostic . span_fatal (
@@ -155,6 +131,43 @@ impl tt_reader_as_reader of reader for tt_reader {
155
131
fn interner ( ) -> @interner:: interner < @str > { self . interner }
156
132
}
157
133
134
+ fn tt_next_token ( & & r: tt_reader ) -> { tok : token:: token , chpos : uint } {
135
+ let ret_val = { tok: r. cur_tok , chpos: r. cur_chpos } ;
136
+ if r. cur . idx >= vec:: len ( r. cur . readme ) {
137
+ /* done with this set; pop */
138
+ alt r. cur . up {
139
+ tt_frame_up ( option:: none) {
140
+ r. cur_tok = token:: EOF ;
141
+ ret ret_val;
142
+ }
143
+ tt_frame_up ( option:: some ( tt_f) ) {
144
+ r. cur <- tt_f;
145
+ /* the above `if` would need to be a `while` if we didn't know
146
+ that the last thing in a `tt_delim` is always a `tt_flat` */
147
+ r. cur . idx += 1 u;
148
+ }
149
+ }
150
+ }
151
+ /* if `tt_delim`s could be 0-length, we'd need to be able to switch
152
+ between popping and pushing until we got to an actual `tt_flat` */
153
+ loop { /* because it's easiest, this handles `tt_delim` not starting
154
+ with a `tt_flat`, even though it won't happen */
155
+ alt r. cur . readme [ r. cur . idx ] {
156
+ tt_delim ( tts) {
157
+ /* TODO: this copy should be a unary move, once they exist */
158
+ r. cur = @{ readme: tts, mut idx: 0 u,
159
+ up: tt_frame_up ( option:: some ( copy r. cur ) ) } ;
160
+ }
161
+ tt_flat ( chpos, tok) {
162
+ r. cur_chpos = chpos; r. cur_tok = tok;
163
+ r. cur . idx += 1 u;
164
+ ret ret_val;
165
+ }
166
+ }
167
+ }
168
+
169
+ }
170
+
158
171
fn get_str_from ( rdr : string_reader , start : uint ) -> str unsafe {
159
172
// I'm pretty skeptical about this subtraction. What if there's a
160
173
// multi-byte character before the mark?
0 commit comments