@@ -70,10 +70,10 @@ impl<'a> Reader for StringReader<'a> {
70
70
ret_val
71
71
}
72
72
fn fatal ( & self , m : & str ) -> ! {
73
- self . span_diagnostic . span_fatal ( self . peek_span , m)
73
+ self . fatal_span ( self . peek_span , m)
74
74
}
75
75
fn err ( & self , m : & str ) {
76
- self . span_diagnostic . span_err ( self . peek_span , m)
76
+ self . err_span ( self . peek_span , m)
77
77
}
78
78
fn peek ( & self ) -> TokenAndSpan {
79
79
// FIXME(pcwalton): Bad copy!
@@ -137,43 +137,52 @@ impl<'a> StringReader<'a> {
137
137
self . curr == Some ( c)
138
138
}
139
139
140
- /// Report a lexical error spanning [`from_pos`, `to_pos`)
141
- fn fatal_span ( & mut self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> ! {
142
- self . peek_span = codemap:: mk_sp ( from_pos, to_pos) ;
143
- self . fatal ( m) ;
140
+ /// Report a fatal lexical error with a given span.
141
+ pub fn fatal_span ( & self , sp : Span , m : & str ) -> ! {
142
+ self . span_diagnostic . span_fatal ( sp, m)
144
143
}
145
144
146
- fn err_span ( & mut self , from_pos : BytePos , to_pos : BytePos , m : & str ) {
147
- self . peek_span = codemap:: mk_sp ( from_pos, to_pos) ;
148
- self . err ( m) ;
145
+ /// Report a lexical error with a given span.
146
+ pub fn err_span ( & self , sp : Span , m : & str ) {
147
+ self . span_diagnostic . span_err ( sp, m)
148
+ }
149
+
150
+ /// Report a fatal error spanning [`from_pos`, `to_pos`).
151
+ fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> ! {
152
+ self . fatal_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
153
+ }
154
+
155
+ /// Report a lexical error spanning [`from_pos`, `to_pos`).
156
+ fn err_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) {
157
+ self . err_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
149
158
}
150
159
151
160
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
152
161
/// escaped character to the error message
153
- fn fatal_span_char ( & mut self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) -> ! {
162
+ fn fatal_span_char ( & self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) -> ! {
154
163
let mut m = m. to_string ( ) ;
155
164
m. push_str ( ": " ) ;
156
165
char:: escape_default ( c, |c| m. push_char ( c) ) ;
157
- self . fatal_span ( from_pos, to_pos, m. as_slice ( ) ) ;
166
+ self . fatal_span_ ( from_pos, to_pos, m. as_slice ( ) ) ;
158
167
}
159
168
160
169
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
161
170
/// escaped character to the error message
162
- fn err_span_char ( & mut self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) {
171
+ fn err_span_char ( & self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) {
163
172
let mut m = m. to_string ( ) ;
164
173
m. push_str ( ": " ) ;
165
174
char:: escape_default ( c, |c| m. push_char ( c) ) ;
166
- self . err_span ( from_pos, to_pos, m. as_slice ( ) ) ;
175
+ self . err_span_ ( from_pos, to_pos, m. as_slice ( ) ) ;
167
176
}
168
177
169
178
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending the
170
179
/// offending string to the error message
171
- fn fatal_span_verbose ( & mut self , from_pos : BytePos , to_pos : BytePos , mut m : String ) -> ! {
180
+ fn fatal_span_verbose ( & self , from_pos : BytePos , to_pos : BytePos , mut m : String ) -> ! {
172
181
m. push_str ( ": " ) ;
173
182
let from = self . byte_offset ( from_pos) . to_uint ( ) ;
174
183
let to = self . byte_offset ( to_pos) . to_uint ( ) ;
175
184
m. push_str ( self . filemap . src . as_slice ( ) . slice ( from, to) ) ;
176
- self . fatal_span ( from_pos, to_pos, m. as_slice ( ) ) ;
185
+ self . fatal_span_ ( from_pos, to_pos, m. as_slice ( ) ) ;
177
186
}
178
187
179
188
/// Advance peek_tok and peek_span to refer to the next token, and
@@ -369,7 +378,7 @@ impl<'a> StringReader<'a> {
369
378
"unterminated block comment"
370
379
} ;
371
380
let last_bpos = self . last_pos ;
372
- self . fatal_span ( start_bpos, last_bpos, msg) ;
381
+ self . fatal_span_ ( start_bpos, last_bpos, msg) ;
373
382
} else if self . curr_is ( '/' ) && self . nextch_is ( '*' ) {
374
383
level += 1 ;
375
384
self . bump ( ) ;
@@ -421,7 +430,7 @@ impl<'a> StringReader<'a> {
421
430
return Some ( rslt) ;
422
431
} else {
423
432
let last_bpos = self . last_pos ;
424
- self . err_span ( start_bpos, last_bpos, "scan_exponent: bad fp literal" ) ;
433
+ self . err_span_ ( start_bpos, last_bpos, "scan_exponent: bad fp literal" ) ;
425
434
rslt. push_str ( "1" ) ; // arbitrary placeholder exponent
426
435
return Some ( rslt) ;
427
436
}
@@ -447,9 +456,10 @@ impl<'a> StringReader<'a> {
447
456
448
457
fn check_float_base ( & mut self , start_bpos : BytePos , last_bpos : BytePos , base : uint ) {
449
458
match base {
450
- 16 u => self . err_span ( start_bpos, last_bpos, "hexadecimal float literal is not supported" ) ,
451
- 8 u => self . err_span ( start_bpos, last_bpos, "octal float literal is not supported" ) ,
452
- 2 u => self . err_span ( start_bpos, last_bpos, "binary float literal is not supported" ) ,
459
+ 16 u => self . err_span_ ( start_bpos, last_bpos,
460
+ "hexadecimal float literal is not supported" ) ,
461
+ 8 u => self . err_span_ ( start_bpos, last_bpos, "octal float literal is not supported" ) ,
462
+ 2 u => self . err_span_ ( start_bpos, last_bpos, "binary float literal is not supported" ) ,
453
463
_ => ( )
454
464
}
455
465
}
@@ -509,15 +519,15 @@ impl<'a> StringReader<'a> {
509
519
}
510
520
if num_str. len ( ) == 0 u {
511
521
let last_bpos = self . last_pos ;
512
- self . err_span ( start_bpos, last_bpos, "no valid digits found for number" ) ;
522
+ self . err_span_ ( start_bpos, last_bpos, "no valid digits found for number" ) ;
513
523
num_str = "1" . to_string ( ) ;
514
524
}
515
525
let parsed = match from_str_radix :: < u64 > ( num_str. as_slice ( ) ,
516
526
base as uint ) {
517
527
Some ( p) => p,
518
528
None => {
519
529
let last_bpos = self . last_pos ;
520
- self . err_span ( start_bpos, last_bpos, "int literal is too large" ) ;
530
+ self . err_span_ ( start_bpos, last_bpos, "int literal is too large" ) ;
521
531
1
522
532
}
523
533
} ;
@@ -573,7 +583,7 @@ impl<'a> StringReader<'a> {
573
583
return token:: LIT_FLOAT ( str_to_ident ( num_str. as_slice ( ) ) , ast:: TyF128 ) ;
574
584
}
575
585
let last_bpos = self . last_pos ;
576
- self . err_span ( start_bpos, last_bpos, "expected `f32`, `f64` or `f128` suffix" ) ;
586
+ self . err_span_ ( start_bpos, last_bpos, "expected `f32`, `f64` or `f128` suffix" ) ;
577
587
}
578
588
if is_float {
579
589
let last_bpos = self . last_pos ;
@@ -583,15 +593,15 @@ impl<'a> StringReader<'a> {
583
593
} else {
584
594
if num_str. len ( ) == 0 u {
585
595
let last_bpos = self . last_pos ;
586
- self . err_span ( start_bpos, last_bpos, "no valid digits found for number" ) ;
596
+ self . err_span_ ( start_bpos, last_bpos, "no valid digits found for number" ) ;
587
597
num_str = "1" . to_string ( ) ;
588
598
}
589
599
let parsed = match from_str_radix :: < u64 > ( num_str. as_slice ( ) ,
590
600
base as uint ) {
591
601
Some ( p) => p,
592
602
None => {
593
603
let last_bpos = self . last_pos ;
594
- self . err_span ( start_bpos, last_bpos, "int literal is too large" ) ;
604
+ self . err_span_ ( start_bpos, last_bpos, "int literal is too large" ) ;
595
605
1
596
606
}
597
607
} ;
@@ -609,11 +619,11 @@ impl<'a> StringReader<'a> {
609
619
for _ in range ( 0 , n_hex_digits) {
610
620
if self . is_eof ( ) {
611
621
let last_bpos = self . last_pos ;
612
- self . fatal_span ( start_bpos, last_bpos, "unterminated numeric character escape" ) ;
622
+ self . fatal_span_ ( start_bpos, last_bpos, "unterminated numeric character escape" ) ;
613
623
}
614
624
if self . curr_is ( delim) {
615
625
let last_bpos = self . last_pos ;
616
- self . err_span ( start_bpos, last_bpos, "numeric character escape is too short" ) ;
626
+ self . err_span_ ( start_bpos, last_bpos, "numeric character escape is too short" ) ;
617
627
break ;
618
628
}
619
629
let c = self . curr . unwrap_or ( '\x00' ) ;
@@ -630,7 +640,7 @@ impl<'a> StringReader<'a> {
630
640
Some ( x) => x,
631
641
None => {
632
642
let last_bpos = self . last_pos ;
633
- self . err_span ( start_bpos, last_bpos, "illegal numeric character escape" ) ;
643
+ self . err_span_ ( start_bpos, last_bpos, "illegal numeric character escape" ) ;
634
644
'?'
635
645
}
636
646
}
@@ -856,16 +866,16 @@ impl<'a> StringReader<'a> {
856
866
let last_bpos = self . last_pos ;
857
867
if token:: is_keyword ( token:: keywords:: Self ,
858
868
keyword_checking_token) {
859
- self . err_span ( start,
860
- last_bpos,
861
- "invalid lifetime name: 'self \
862
- is no longer a special lifetime") ;
869
+ self . err_span_ ( start,
870
+ last_bpos,
871
+ "invalid lifetime name: 'self \
872
+ is no longer a special lifetime") ;
863
873
} else if token:: is_any_keyword ( keyword_checking_token) &&
864
874
!token:: is_keyword ( token:: keywords:: Static ,
865
875
keyword_checking_token) {
866
- self . err_span ( start,
867
- last_bpos,
868
- "invalid lifetime name" ) ;
876
+ self . err_span_ ( start,
877
+ last_bpos,
878
+ "invalid lifetime name" ) ;
869
879
}
870
880
return token:: LIFETIME ( ident) ;
871
881
}
@@ -922,8 +932,8 @@ impl<'a> StringReader<'a> {
922
932
while !self_. curr_is ( '"' ) {
923
933
if self_. is_eof ( ) {
924
934
let last_pos = self_. last_pos ;
925
- self_. fatal_span ( start, last_pos,
926
- "unterminated double quote byte string" ) ;
935
+ self_. fatal_span_ ( start, last_pos,
936
+ "unterminated double quote byte string" ) ;
927
937
}
928
938
929
939
let ch_start = self_. last_pos ;
@@ -947,7 +957,7 @@ impl<'a> StringReader<'a> {
947
957
948
958
if self_. is_eof ( ) {
949
959
let last_pos = self_. last_pos ;
950
- self_. fatal_span ( start_bpos, last_pos, "unterminated raw string" ) ;
960
+ self_. fatal_span_ ( start_bpos, last_pos, "unterminated raw string" ) ;
951
961
} else if !self_. curr_is ( '"' ) {
952
962
let last_pos = self_. last_pos ;
953
963
let ch = self_. curr . unwrap ( ) ;
@@ -963,7 +973,7 @@ impl<'a> StringReader<'a> {
963
973
match self_. curr {
964
974
None => {
965
975
let last_pos = self_. last_pos ;
966
- self_. fatal_span ( start_bpos, last_pos, "unterminated raw string" )
976
+ self_. fatal_span_ ( start_bpos, last_pos, "unterminated raw string" )
967
977
} ,
968
978
Some ( '"' ) => {
969
979
content_end_bpos = self_. last_pos ;
@@ -997,7 +1007,7 @@ impl<'a> StringReader<'a> {
997
1007
while !self . curr_is ( '"' ) {
998
1008
if self . is_eof ( ) {
999
1009
let last_bpos = self . last_pos ;
1000
- self . fatal_span ( start_bpos, last_bpos, "unterminated double quote string" ) ;
1010
+ self . fatal_span_ ( start_bpos, last_bpos, "unterminated double quote string" ) ;
1001
1011
}
1002
1012
1003
1013
let ch_start = self . last_pos ;
@@ -1020,7 +1030,7 @@ impl<'a> StringReader<'a> {
1020
1030
1021
1031
if self . is_eof ( ) {
1022
1032
let last_bpos = self . last_pos ;
1023
- self . fatal_span ( start_bpos, last_bpos, "unterminated raw string" ) ;
1033
+ self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) ;
1024
1034
} else if !self . curr_is ( '"' ) {
1025
1035
let last_bpos = self . last_pos ;
1026
1036
let curr_char = self . curr . unwrap ( ) ;
@@ -1035,7 +1045,7 @@ impl<'a> StringReader<'a> {
1035
1045
' outer: loop {
1036
1046
if self . is_eof ( ) {
1037
1047
let last_bpos = self . last_pos ;
1038
- self . fatal_span ( start_bpos, last_bpos, "unterminated raw string" ) ;
1048
+ self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) ;
1039
1049
}
1040
1050
if self . curr_is ( '"' ) {
1041
1051
content_end_bpos = self . last_pos ;
0 commit comments