@@ -58,7 +58,25 @@ In most cases, you should use the `.. name` tail capture term to perform this ta
58
58
*/
59
59
pub struct Everything < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
60
60
61
- impl < ' a , Output > ScanFromStr < ' a > for Everything < ' a , Output > where & ' a str : Into < Output > {
61
+ #[ cfg( str_into_output_extra_broken) ]
62
+ impl < ' a > ScanFromStr < ' a > for Everything < ' a , & ' a str > {
63
+ type Output = & ' a str ;
64
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
65
+ Ok ( ( s. into ( ) , s. len ( ) ) )
66
+ }
67
+ }
68
+
69
+ #[ cfg( str_into_output_extra_broken) ]
70
+ impl < ' a > ScanFromStr < ' a > for Everything < ' a , String > {
71
+ type Output = String ;
72
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
73
+ Ok ( ( s. into ( ) , s. len ( ) ) )
74
+ }
75
+ }
76
+
77
+ #[ cfg( not( str_into_output_extra_broken) ) ]
78
+ impl < ' a , Output > ScanFromStr < ' a > for Everything < ' a , Output >
79
+ where & ' a str : Into < Output > {
62
80
type Output = Output ;
63
81
fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
64
82
Ok ( ( s. into ( ) , s. len ( ) ) )
@@ -69,9 +87,9 @@ impl<'a, Output> ScanFromStr<'a> for Everything<'a, Output> where &'a str: Into<
69
87
#[ test]
70
88
fn test_everything ( ) {
71
89
// That's the scanner named `Everything`, not literally everything.
72
- assert_match ! ( Everything :: scan_from( "" ) , Ok ( ( "" , 0 ) ) ) ;
73
- assert_match ! ( Everything :: scan_from( "で" ) , Ok ( ( "で" , 3 ) ) ) ;
74
- assert_match ! ( Everything :: scan_from( "うまいー うまいー ぼうぼうぼうぼう" ) , Ok ( ( "うまいー うまいー ぼうぼうぼうぼう" , 54 ) ) ) ;
90
+ assert_match ! ( Everything :: < & str > :: scan_from( "" ) , Ok ( ( "" , 0 ) ) ) ;
91
+ assert_match ! ( Everything :: < & str > :: scan_from( "で" ) , Ok ( ( "で" , 3 ) ) ) ;
92
+ assert_match ! ( Everything :: < & str > :: scan_from( "うまいー うまいー ぼうぼうぼうぼう" ) , Ok ( ( "うまいー うまいー ぼうぼうぼうぼう" , 54 ) ) ) ;
75
93
}
76
94
77
95
/**
@@ -103,6 +121,45 @@ Specifically, this will match a single `XID_Start` character (or underscore) fol
103
121
*/
104
122
pub struct Ident < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
105
123
124
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
125
+ #[ cfg( str_into_output_extra_broken) ]
126
+ impl < ' a > ScanFromStr < ' a > for Ident < ' a , & ' a str > {
127
+ type Output = & ' a str ;
128
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
129
+ match IDENT_RE . find ( s) {
130
+ Some ( ( a, b) ) => {
131
+ let word = & s[ a..b] ;
132
+ let tail = & s[ b..] ;
133
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
134
+ } ,
135
+ None => {
136
+ // Err(ScanErrorKind::Syntax(Some("expected identifier")))
137
+ Err ( ScanErrorKind :: SyntaxNoMessage )
138
+ } ,
139
+ }
140
+ }
141
+ }
142
+
143
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
144
+ #[ cfg( str_into_output_extra_broken) ]
145
+ impl < ' a > ScanFromStr < ' a > for Ident < ' a , String > {
146
+ type Output = String ;
147
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
148
+ match IDENT_RE . find ( s) {
149
+ Some ( ( a, b) ) => {
150
+ let word = & s[ a..b] ;
151
+ let tail = & s[ b..] ;
152
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
153
+ } ,
154
+ None => {
155
+ // Err(ScanErrorKind::Syntax(Some("expected identifier")))
156
+ Err ( ScanErrorKind :: SyntaxNoMessage )
157
+ } ,
158
+ }
159
+ }
160
+ }
161
+
162
+ #[ cfg( not( str_into_output_extra_broken) ) ]
106
163
// FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
107
164
impl < ' a , Output > ScanFromStr < ' a > for Ident < ' a , Output >
108
165
where & ' a str : Into < Output > {
@@ -143,6 +200,31 @@ Note that this is effectively equivalent to the `Everything` matcher when used w
143
200
*/
144
201
pub struct Line < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
145
202
203
+ #[ cfg( str_into_output_extra_broken) ]
204
+ impl < ' a > ScanFromStr < ' a > for Line < ' a , & ' a str > {
205
+ type Output = & ' a str ;
206
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
207
+ const EX_MSG : & ' static str = "line scanning regex failed to match anything" ;
208
+ let cap = LINE_RE . captures ( s) . expect ( EX_MSG ) ;
209
+ let ( _, b) = cap. pos ( 0 ) . expect ( EX_MSG ) ;
210
+ let ( c, d) = cap. pos ( 1 ) . expect ( EX_MSG ) ;
211
+ Ok ( ( s[ c..d] . into ( ) , b) )
212
+ }
213
+ }
214
+
215
+ #[ cfg( str_into_output_extra_broken) ]
216
+ impl < ' a > ScanFromStr < ' a > for Line < ' a , String > {
217
+ type Output = String ;
218
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
219
+ const EX_MSG : & ' static str = "line scanning regex failed to match anything" ;
220
+ let cap = LINE_RE . captures ( s) . expect ( EX_MSG ) ;
221
+ let ( _, b) = cap. pos ( 0 ) . expect ( EX_MSG ) ;
222
+ let ( c, d) = cap. pos ( 1 ) . expect ( EX_MSG ) ;
223
+ Ok ( ( s[ c..d] . into ( ) , b) )
224
+ }
225
+ }
226
+
227
+ #[ cfg( not( str_into_output_extra_broken) ) ]
146
228
impl < ' a , Output > ScanFromStr < ' a > for Line < ' a , Output > where & ' a str : Into < Output > {
147
229
type Output = Output ;
148
230
fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
@@ -157,11 +239,11 @@ impl<'a, Output> ScanFromStr<'a> for Line<'a, Output> where &'a str: Into<Output
157
239
#[ cfg( test) ]
158
240
#[ test]
159
241
fn test_line ( ) {
160
- assert_match ! ( Line :: scan_from( "" ) , Ok ( ( "" , 0 ) ) ) ;
161
- assert_match ! ( Line :: scan_from( "abc def" ) , Ok ( ( "abc def" , 7 ) ) ) ;
162
- assert_match ! ( Line :: scan_from( "abc\n def" ) , Ok ( ( "abc" , 4 ) ) ) ;
163
- assert_match ! ( Line :: scan_from( "abc\r \n def" ) , Ok ( ( "abc" , 5 ) ) ) ;
164
- assert_match ! ( Line :: scan_from( "abc\r def" ) , Ok ( ( "abc" , 4 ) ) ) ;
242
+ assert_match ! ( Line :: < & str > :: scan_from( "" ) , Ok ( ( "" , 0 ) ) ) ;
243
+ assert_match ! ( Line :: < & str > :: scan_from( "abc def" ) , Ok ( ( "abc def" , 7 ) ) ) ;
244
+ assert_match ! ( Line :: < & str > :: scan_from( "abc\n def" ) , Ok ( ( "abc" , 4 ) ) ) ;
245
+ assert_match ! ( Line :: < & str > :: scan_from( "abc\r \n def" ) , Ok ( ( "abc" , 5 ) ) ) ;
246
+ assert_match ! ( Line :: < & str > :: scan_from( "abc\r def" ) , Ok ( ( "abc" , 4 ) ) ) ;
165
247
}
166
248
167
249
/**
@@ -172,6 +254,41 @@ This *will not* match an empty sequence; there must be at least one non-space ch
172
254
pub struct NonSpace < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
173
255
174
256
// FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
257
+ #[ cfg( str_into_output_extra_broken) ]
258
+ impl < ' a > ScanFromStr < ' a > for NonSpace < ' a , & ' a str > {
259
+ type Output = & ' a str ;
260
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
261
+ match NONSPACE_RE . find ( s) {
262
+ Some ( ( a, b) ) => {
263
+ let word = & s[ a..b] ;
264
+ let tail = & s[ b..] ;
265
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
266
+ } ,
267
+ // None => Err(ScanErrorKind::Syntax(Some("expected at least one non-space character"))),
268
+ None => Err ( ScanErrorKind :: SyntaxNoMessage )
269
+ }
270
+ }
271
+ }
272
+
273
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
274
+ #[ cfg( str_into_output_extra_broken) ]
275
+ impl < ' a > ScanFromStr < ' a > for NonSpace < ' a , String > {
276
+ type Output = String ;
277
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
278
+ match NONSPACE_RE . find ( s) {
279
+ Some ( ( a, b) ) => {
280
+ let word = & s[ a..b] ;
281
+ let tail = & s[ b..] ;
282
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
283
+ } ,
284
+ // None => Err(ScanErrorKind::Syntax(Some("expected at least one non-space character"))),
285
+ None => Err ( ScanErrorKind :: SyntaxNoMessage )
286
+ }
287
+ }
288
+ }
289
+
290
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
291
+ #[ cfg( not( str_into_output_extra_broken) ) ]
175
292
impl < ' a , Output > ScanFromStr < ' a > for NonSpace < ' a , Output >
176
293
where & ' a str : Into < Output > {
177
294
type Output = Output ;
@@ -215,6 +332,41 @@ Note that this *includes* non-ASCII decimal characters, meaning it will scan num
215
332
pub struct Number < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
216
333
217
334
// FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
335
+ #[ cfg( str_into_output_extra_broken) ]
336
+ impl < ' a > ScanFromStr < ' a > for Number < ' a , & ' a str > {
337
+ type Output = & ' a str ;
338
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
339
+ match NUMBER_RE . find ( s) {
340
+ Some ( ( a, b) ) => {
341
+ let word = & s[ a..b] ;
342
+ let tail = & s[ b..] ;
343
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
344
+ } ,
345
+ // None => Err(ScanErrorKind::Syntax(Some("expected a number"))),
346
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
347
+ }
348
+ }
349
+ }
350
+
351
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
352
+ #[ cfg( str_into_output_extra_broken) ]
353
+ impl < ' a > ScanFromStr < ' a > for Number < ' a , String > {
354
+ type Output = String ;
355
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
356
+ match NUMBER_RE . find ( s) {
357
+ Some ( ( a, b) ) => {
358
+ let word = & s[ a..b] ;
359
+ let tail = & s[ b..] ;
360
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
361
+ } ,
362
+ // None => Err(ScanErrorKind::Syntax(Some("expected a number"))),
363
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
364
+ }
365
+ }
366
+ }
367
+
368
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
369
+ #[ cfg( not( str_into_output_extra_broken) ) ]
218
370
impl < ' a , Output > ScanFromStr < ' a > for Number < ' a , Output >
219
371
where & ' a str : Into < Output > {
220
372
type Output = Output ;
@@ -378,6 +530,41 @@ Specifically, this will match a continuous run of alphabetic, digit, punctuation
378
530
pub struct Word < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
379
531
380
532
// FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
533
+ #[ cfg( str_into_output_extra_broken) ]
534
+ impl < ' a > ScanFromStr < ' a > for Word < ' a , & ' a str > {
535
+ type Output = & ' a str ;
536
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
537
+ match WORD_RE . find ( s) {
538
+ Some ( ( a, b) ) => {
539
+ let word = & s[ a..b] ;
540
+ let tail = & s[ b..] ;
541
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
542
+ } ,
543
+ // None => Err(ScanErrorKind::Syntax(Some("expected a word"))),
544
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
545
+ }
546
+ }
547
+ }
548
+
549
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
550
+ #[ cfg( str_into_output_extra_broken) ]
551
+ impl < ' a > ScanFromStr < ' a > for Word < ' a , String > {
552
+ type Output = String ;
553
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
554
+ match WORD_RE . find ( s) {
555
+ Some ( ( a, b) ) => {
556
+ let word = & s[ a..b] ;
557
+ let tail = & s[ b..] ;
558
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
559
+ } ,
560
+ // None => Err(ScanErrorKind::Syntax(Some("expected a word"))),
561
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
562
+ }
563
+ }
564
+ }
565
+
566
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
567
+ #[ cfg( not( str_into_output_extra_broken) ) ]
381
568
impl < ' a , Output > ScanFromStr < ' a > for Word < ' a , Output >
382
569
where & ' a str : Into < Output > {
383
570
type Output = Output ;
@@ -420,6 +607,43 @@ Specifically, this will match a word (a continuous run of alphabetic, digit, pun
420
607
pub struct Wordish < ' a , Output =& ' a str > ( PhantomData < ( & ' a ( ) , Output ) > ) ;
421
608
422
609
// FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
610
+ #[ cfg( str_into_output_extra_broken) ]
611
+ impl < ' a > ScanFromStr < ' a > for Wordish < ' a , & ' a str > {
612
+ type Output = & ' a str ;
613
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
614
+ // TODO: This should be modified to grab an entire *grapheme cluster* in the event it can't find a word or number.
615
+ match WORDISH_RE . find ( s) {
616
+ Some ( ( a, b) ) => {
617
+ let word = & s[ a..b] ;
618
+ let tail = & s[ b..] ;
619
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
620
+ } ,
621
+ // None => Err(ScanErrorKind::Syntax(Some("expected a word, number or some other character"))),
622
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
623
+ }
624
+ }
625
+ }
626
+
627
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
628
+ #[ cfg( str_into_output_extra_broken) ]
629
+ impl < ' a > ScanFromStr < ' a > for Wordish < ' a , String > {
630
+ type Output = String ;
631
+ fn scan_from ( s : & ' a str ) -> Result < ( Self :: Output , usize ) , ScanErrorKind > {
632
+ // TODO: This should be modified to grab an entire *grapheme cluster* in the event it can't find a word or number.
633
+ match WORDISH_RE . find ( s) {
634
+ Some ( ( a, b) ) => {
635
+ let word = & s[ a..b] ;
636
+ let tail = & s[ b..] ;
637
+ Ok ( ( word. into ( ) , s. subslice_offset ( tail) . unwrap ( ) ) )
638
+ } ,
639
+ // None => Err(ScanErrorKind::Syntax(Some("expected a word, number or some other character"))),
640
+ None => Err ( ScanErrorKind :: SyntaxNoMessage ) ,
641
+ }
642
+ }
643
+ }
644
+
645
+ // FIXME: Error message omitted due to https://github.com/rust-lang/rust/issues/26448.
646
+ #[ cfg( not( str_into_output_extra_broken) ) ]
423
647
impl < ' a , Output > ScanFromStr < ' a > for Wordish < ' a , Output >
424
648
where & ' a str : Into < Output > {
425
649
type Output = Output ;
0 commit comments