@@ -61,6 +61,7 @@ fn has_repeating(str string, repeats []rune) bool {
61
61
62
62
fn (c Checker) check_number (num ast.Number) ? {
63
63
lit := num.text
64
+ lit_lower_case := lit.to_lower ()
64
65
if lit in ['0' , '0.0' , '+0' , '-0' , '+0.0' , '-0.0' , '0e0' , '+0e0' , '-0e0' , '0e00' ] {
65
66
return
66
67
}
@@ -78,8 +79,8 @@ fn (c Checker) check_number(num ast.Number) ? {
78
79
79
80
mut hex_bin_oct := is_hex_bin_oct (lit)
80
81
mut is_bin, mut is_oct, mut is_hex := false , false , false
81
- is_float := lit. to_lower () .all_before ('e' ).contains ('.' )
82
- has_exponent_notation := lit. to_lower () .contains ('e' )
82
+ is_float := lit_lower_case .all_before ('e' ).contains ('.' )
83
+ has_exponent_notation := lit_lower_case .contains ('e' )
83
84
float_decimal_index := lit.index ('.' ) or { - 1 }
84
85
// mut is_first_digit := byte(lit[0]).is_digit()
85
86
mut ascii := byte (lit[0 ]).ascii_str ()
@@ -160,15 +161,16 @@ fn (c Checker) check_number(num ast.Number) ? {
160
161
}
161
162
162
163
if has_exponent_notation {
163
- if lit.to_lower ().all_after ('e' ).starts_with ('_' ) {
164
+ if lit_lower_case.all_after ('e' ).starts_with ('_' )
165
+ || lit_lower_case.all_before ('e' ).ends_with ('_' ) {
164
166
return error (@MOD + '.' + @STRUCT + '.' + @FN +
165
- ' the exponent in "$lit " can not start with an underscore in ...${c.excerpt(num.pos)} ...' )
167
+ ' the exponent in "$lit " can not start nor end with an underscore in ...${c.excerpt(num.pos)} ...' )
166
168
}
167
- if lit. to_lower () .all_after ('e' ).contains ('.' ) {
169
+ if lit_lower_case .all_after ('e' ).contains ('.' ) {
168
170
return error (@MOD + '.' + @STRUCT + '.' + @FN +
169
171
' numbers like "$lit " (with exponent) can not have a decimal point in ...${c.excerpt(num.pos)} ...' )
170
172
}
171
- if ! is_hex && lit. to_lower () .count ('e' ) > 1 {
173
+ if ! is_hex && lit_lower_case .count ('e' ) > 1 {
172
174
return error (@MOD + '.' + @STRUCT + '.' + @FN +
173
175
' numbers like "$lit " (with exponent) can only have one exponent in ...${c.excerpt(num.pos)} ...' )
174
176
}
@@ -189,9 +191,9 @@ fn (c Checker) check_number(num ast.Number) ? {
189
191
return error (@MOD + '.' + @STRUCT + '.' + @FN +
190
192
' numbers like "$lit " (float) can not have underscores before or after the decimal point in ...${c.excerpt(num.pos)} ...' )
191
193
}
192
- if lit .contains ('e.' ) || lit.contains ('.e' ) || lit. contains ( 'E.' ) || lit. contains ( '.E ' ) {
194
+ if lit_lower_case .contains ('e.' ) || lit.contains ('.e' ) {
193
195
return error (@MOD + '.' + @STRUCT + '.' + @FN +
194
- ' numbers like "$lit " (float) can not have underscores before or after the decimal point in ...${c.excerpt(num.pos)} ...' )
196
+ ' numbers like "$lit " (float) can not have decimal points on either side of the exponent notation in ...${c.excerpt(num.pos)} ...' )
195
197
}
196
198
} else {
197
199
if lit.len > 1 && lit.starts_with ('0' ) && lit[1 ] ! in [`b` , `o` , `x` ] {
0 commit comments