@@ -10,22 +10,21 @@ use rustc_span::Span;
10
10
11
11
use std:: ascii;
12
12
13
+ // njn: how much of this will be left?
13
14
pub enum LitError {
14
15
NotLiteral ,
15
16
LexerError ,
16
- InvalidSuffix ,
17
- InvalidIntSuffix ,
18
- InvalidFloatSuffix ,
19
- NonDecimalFloat ( u32 ) ,
20
17
IntTooLarge ,
21
18
}
22
19
23
20
impl LitKind {
24
21
/// Converts literal token into a semantic literal.
25
22
pub fn from_token_lit ( lit : token:: Lit ) -> Result < LitKind , LitError > {
26
23
let token:: Lit { kind, symbol, suffix } = lit;
24
+ // njn: could even move the suffix into `kind`...
27
25
if suffix. is_some ( ) && !kind. may_have_suffix ( ) {
28
- return Err ( LitError :: InvalidSuffix ) ;
26
+ // njn: yuk
27
+ return Err ( LitError :: LexerError ) ;
29
28
}
30
29
31
30
Ok ( match kind {
@@ -259,33 +258,23 @@ fn strip_underscores(symbol: Symbol) -> Symbol {
259
258
symbol
260
259
}
261
260
262
- fn filtered_float_lit (
263
- symbol : Symbol ,
264
- suffix : Option < Symbol > ,
265
- base : u32 ,
266
- ) -> Result < LitKind , LitError > {
267
- debug ! ( "filtered_float_lit: {:?}, {:?}, {:?}" , symbol, suffix, base) ;
268
- if base != 10 {
269
- return Err ( LitError :: NonDecimalFloat ( base) ) ;
270
- }
261
+ fn float_lit ( symbol : Symbol , suffix : Option < Symbol > ) -> Result < LitKind , LitError > {
262
+ debug ! ( "float_lit: {:?}, {:?}" , symbol, suffix) ;
263
+ let symbol = strip_underscores ( symbol) ;
264
+
271
265
Ok ( match suffix {
272
266
Some ( suf) => LitKind :: Float (
273
267
symbol,
274
268
ast:: LitFloatType :: Suffixed ( match suf {
275
269
sym:: f32 => ast:: FloatTy :: F32 ,
276
270
sym:: f64 => ast:: FloatTy :: F64 ,
277
- _ => return Err ( LitError :: InvalidFloatSuffix ) ,
271
+ _ => return Err ( LitError :: LexerError ) ,
278
272
} ) ,
279
273
) ,
280
274
None => LitKind :: Float ( symbol, ast:: LitFloatType :: Unsuffixed ) ,
281
275
} )
282
276
}
283
277
284
- fn float_lit ( symbol : Symbol , suffix : Option < Symbol > ) -> Result < LitKind , LitError > {
285
- debug ! ( "float_lit: {:?}, {:?}" , symbol, suffix) ;
286
- filtered_float_lit ( strip_underscores ( symbol) , suffix, 10 )
287
- }
288
-
289
278
fn integer_lit ( symbol : Symbol , suffix : Option < Symbol > ) -> Result < LitKind , LitError > {
290
279
debug ! ( "integer_lit: {:?}, {:?}" , symbol, suffix) ;
291
280
let symbol = strip_underscores ( symbol) ;
@@ -312,10 +301,11 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
312
301
sym:: u32 => ast:: LitIntType :: Unsigned ( ast:: UintTy :: U32 ) ,
313
302
sym:: u64 => ast:: LitIntType :: Unsigned ( ast:: UintTy :: U64 ) ,
314
303
sym:: u128 => ast:: LitIntType :: Unsigned ( ast:: UintTy :: U128 ) ,
315
- // `1f64` and `2f32` etc. are valid float literals, and
316
- // `fxxx` looks more like an invalid float literal than invalid integer literal.
317
- _ if suf. as_str ( ) . starts_with ( 'f' ) => return filtered_float_lit ( symbol, suffix, base) ,
318
- _ => return Err ( LitError :: InvalidIntSuffix ) ,
304
+ _ =>
305
+ //return Err(LitError::LexerError), // njn: hmm
306
+ {
307
+ return Ok ( ast:: LitKind :: Err ) ;
308
+ }
319
309
} ,
320
310
_ => ast:: LitIntType :: Unsuffixed ,
321
311
} ;
0 commit comments