@@ -19,22 +19,22 @@ macro_rules! is {
19
19
( $p: expr, BindingIdent ) => { {
20
20
let ctx = $p. ctx( ) ;
21
21
match $p. input. cur( ) {
22
- Some ( & crate :: token :: Word ( ref w) ) => !ctx. is_reserved( w) ,
22
+ Some ( & Word ( ref w) ) => !ctx. is_reserved( w) ,
23
23
_ => false ,
24
24
}
25
25
} } ;
26
26
27
27
( $p: expr, IdentRef ) => { {
28
28
let ctx = $p. ctx( ) ;
29
29
match $p. input. cur( ) {
30
- Some ( & crate :: token :: Word ( ref w) ) => !ctx. is_reserved( w) ,
30
+ Some ( & Word ( ref w) ) => !ctx. is_reserved( w) ,
31
31
_ => false ,
32
32
}
33
33
} } ;
34
34
35
35
( $p: expr, IdentName ) => { {
36
36
match $p. input. cur( ) {
37
- Some ( & crate :: token :: Word ( ..) ) => true ,
37
+ Some ( & Word ( ..) ) => true ,
38
38
_ => false ,
39
39
}
40
40
} } ;
@@ -77,33 +77,29 @@ macro_rules! is {
77
77
( $p: expr, $t: tt) => {
78
78
is_exact!( $p, $t)
79
79
} ;
80
-
81
- ( $p: expr, $t: tt | $( $rest: tt) * ) => { {
82
- is!( $p, $t) || is!( $p, $( $rest) * )
83
- } } ;
84
80
}
85
81
86
82
#[ allow( unused) ]
87
83
macro_rules! peeked_is {
88
84
( $p: expr, BindingIdent ) => { {
89
85
let ctx = $p. ctx( ) ;
90
86
match peek!( $p) {
91
- Some ( & crate :: token :: Word ( ref w) ) => !ctx. is_reserved( w) ,
87
+ Some ( & Word ( ref w) ) => !ctx. is_reserved( w) ,
92
88
_ => false ,
93
89
}
94
90
} } ;
95
91
96
92
( $p: expr, IdentRef ) => { {
97
93
let ctx = $p. ctx( ) ;
98
94
match peek!( $p) {
99
- Some ( & crate :: token :: Word ( ref w) ) => !ctx. is_reserved( w) ,
95
+ Some ( & Word ( ref w) ) => !ctx. is_reserved( w) ,
100
96
_ => false ,
101
97
}
102
98
} } ;
103
99
104
100
( $p: expr, IdentName ) => { {
105
101
match peek!( $p) {
106
- Some ( & crate :: token :: Word ( ..) ) => true ,
102
+ Some ( & Word ( ..) ) => true ,
107
103
_ => false ,
108
104
}
109
105
} } ;
@@ -125,10 +121,6 @@ macro_rules! peeked_is {
125
121
_ => false ,
126
122
}
127
123
} ;
128
-
129
- ( $p: expr, $t: tt | $( $rest: tt) * ) => {
130
- peeked_is!( $p, $t) || peeked_is!( $p, $( $rest) * )
131
- } ;
132
124
}
133
125
134
126
/// Returns true on eof.
@@ -138,6 +130,15 @@ macro_rules! eof {
138
130
} ;
139
131
}
140
132
133
+ macro_rules! is_one_of {
134
+ ( $p: expr, $( $t: tt) ,+) => { {
135
+ false
136
+ $(
137
+ || is!( $p, $t)
138
+ ) *
139
+ } } ;
140
+ }
141
+
141
142
// This will panic if current != token
142
143
macro_rules! assert_and_bump {
143
144
( $p: expr, $t: tt) => { {
@@ -160,6 +161,9 @@ macro_rules! assert_and_bump {
160
161
/// if token has data like string.
161
162
macro_rules! eat {
162
163
( $p: expr, ';' ) => { {
164
+ if cfg!( feature = "debug" ) {
165
+ tracing:: trace!( "eat(';'): cur={:?}" , cur!( $p, false ) ) ;
166
+ }
163
167
match $p. input. cur( ) {
164
168
Some ( & Token :: Semi ) => {
165
169
$p. input. bump( ) ;
@@ -206,11 +210,7 @@ macro_rules! expect {
206
210
const TOKEN : & Token = & token_including_semi!( $t) ;
207
211
if !eat!( $p, $t) {
208
212
let cur = $p. input. dump_cur( ) ;
209
- syntax_error!(
210
- $p,
211
- $p. input. cur_span( ) ,
212
- crate :: error:: SyntaxError :: Expected ( TOKEN , cur)
213
- )
213
+ syntax_error!( $p, $p. input. cur_span( ) , SyntaxError :: Expected ( TOKEN , cur) )
214
214
}
215
215
} } ;
216
216
}
@@ -220,11 +220,7 @@ macro_rules! expect_exact {
220
220
const TOKEN : & Token = & token_including_semi!( $t) ;
221
221
if !eat_exact!( $p, $t) {
222
222
let cur = $p. input. dump_cur( ) ;
223
- syntax_error!(
224
- $p,
225
- $p. input. cur_span( ) ,
226
- crate :: error:: SyntaxError :: Expected ( TOKEN , cur)
227
- )
223
+ syntax_error!( $p, $p. input. cur_span( ) , SyntaxError :: Expected ( TOKEN , cur) )
228
224
}
229
225
} } ;
230
226
}
@@ -295,9 +291,6 @@ macro_rules! bump {
295
291
$p. input. knows_cur( ) ,
296
292
"parser should not call bump() without knowing current token"
297
293
) ;
298
- if cfg!( feature = "debug" ) {
299
- tracing:: info!( "Bump: {:?}" , $p. input. cur( ) ) ;
300
- }
301
294
$p. input. bump( )
302
295
} } ;
303
296
}
@@ -384,13 +377,16 @@ macro_rules! syntax_error {
384
377
}
385
378
}
386
379
}
387
- tracing:: error!(
388
- "Syntax error called from {}:{}:{}\n Current token = {:?}" ,
389
- file!( ) ,
390
- line!( ) ,
391
- column!( ) ,
392
- $p. input. cur( )
393
- ) ;
380
+
381
+ if cfg!( feature = "debug" ) {
382
+ tracing:: error!(
383
+ "Syntax error called from {}:{}:{}\n Current token = {:?}" ,
384
+ file!( ) ,
385
+ line!( ) ,
386
+ column!( ) ,
387
+ $p. input. cur( )
388
+ ) ;
389
+ }
394
390
return Err ( err. into( ) ) ;
395
391
} } ;
396
392
}
0 commit comments