vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi 2022-11-15 21:53:13 +08:00 committed by GitHub
parent 56239b4a23
commit 017ace6ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
859 changed files with 7156 additions and 7135 deletions

View file

@ -91,11 +91,11 @@ fn (c Checker) check_number(num ast.Number) ! {
if lit.contains('_') {
if lit.starts_with('_') || lit.ends_with('_') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start or end with `_` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start or end with `_` in ...${c.excerpt(num.pos)}...')
}
if lit.contains('__') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not have more than one underscore (`_`) in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not have more than one underscore (`_`) in ...${c.excerpt(num.pos)}...')
}
}
@ -114,34 +114,34 @@ fn (c Checker) check_number(num ast.Number) ! {
if hex_bin_oct {
ascii = u8(lit[0]).ascii_str()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (hex, octal and binary) can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (hex, octal and binary) can not start with `${ascii}` in ...${c.excerpt(num.pos)}...')
}
if lit.len > 1 && lit_sans_sign.starts_with('0') && !lit_sans_sign.starts_with('0.') {
ascii = u8(lit_sans_sign[0]).ascii_str()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start with `${ascii}` in ...${c.excerpt(num.pos)}...')
}
} else {
if !hex_bin_oct {
if !is_float && lit[0] == `0` {
if lit[1] in [`B`, `O`, `X`] {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" only lowercase notation in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" only lowercase notation in ...${c.excerpt(num.pos)}...')
}
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start with a zero in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start with a zero in ...${c.excerpt(num.pos)}...')
}
if is_float && lit[0] == `0` && float_decimal_index > 1 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start with a zero in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start with a zero in ...${c.excerpt(num.pos)}...')
}
}
}
if has_repeating(lit, [`_`, `.`, `b`, `o`, `x`]) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not have $scanner.digit_extras as repeating characters in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not have ${scanner.digit_extras} as repeating characters in ...${c.excerpt(num.pos)}...')
}
if hex_bin_oct {
@ -154,23 +154,23 @@ fn (c Checker) check_number(num ast.Number) ! {
if lit_sans_sign_and_type_prefix.starts_with('_')
|| lit_sans_sign_and_type_prefix.ends_with('_') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start or end with `_` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start or end with `_` in ...${c.excerpt(num.pos)}...')
}
if is_bin {
if !c.is_valid_binary_literal(lit_sans_sign_and_type_prefix) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid binary number in ...${c.excerpt(num.pos)}...')
' "${lit}" is not a valid binary number in ...${c.excerpt(num.pos)}...')
}
} else if is_oct {
if !c.is_valid_octal_literal(lit_sans_sign_and_type_prefix) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid octal number in ...${c.excerpt(num.pos)}...')
' "${lit}" is not a valid octal number in ...${c.excerpt(num.pos)}...')
}
} else {
if !c.is_valid_hex_literal(lit_sans_sign_and_type_prefix) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid hexadecimal number in ...${c.excerpt(num.pos)}...')
' "${lit}" is not a valid hexadecimal number in ...${c.excerpt(num.pos)}...')
}
}
}
@ -179,50 +179,50 @@ fn (c Checker) check_number(num ast.Number) ! {
if lit_lower_case.all_after('e').starts_with('_')
|| lit_lower_case.all_before('e').ends_with('_') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' the exponent in "$lit" can not start nor end with an underscore in ...${c.excerpt(num.pos)}...')
' the exponent in "${lit}" can not start nor end with an underscore in ...${c.excerpt(num.pos)}...')
}
if lit_lower_case.all_after('e').contains('.') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (with exponent) can not have a decimal point in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (with exponent) can not have a decimal point in ...${c.excerpt(num.pos)}...')
}
if !is_hex && lit_lower_case.count('e') > 1 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (with exponent) can only have one exponent in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (with exponent) can only have one exponent in ...${c.excerpt(num.pos)}...')
}
}
if is_float {
if lit.count('.') > 1 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can only have one decimal point in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (float) can only have one decimal point in ...${c.excerpt(num.pos)}...')
}
last := lit[lit.len - 1]
if last in scanner.digit_extras {
ascii = u8(last).ascii_str()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not end with `$ascii` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (float) can not end with `${ascii}` in ...${c.excerpt(num.pos)}...')
}
if lit.contains('_.') || lit.contains('._') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not have underscores before or after the decimal point in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (float) can not have underscores before or after the decimal point in ...${c.excerpt(num.pos)}...')
}
if lit_lower_case.contains('e.') || lit.contains('.e') {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not have decimal points on either side of the exponent notation in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (float) can not have decimal points on either side of the exponent notation in ...${c.excerpt(num.pos)}...')
}
// Check if it contains other chars than the allowed
for r in lit {
if r !in [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`, `-`, `+`,
`_`] {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not contain `${u8(r).ascii_str()}` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" (float) can not contain `${u8(r).ascii_str()}` in ...${c.excerpt(num.pos)}...')
}
}
} else {
if lit.len > 1 && lit.starts_with('0') && lit[1] !in [`b`, `o`, `x`] {
ascii = u8(lit[0]).ascii_str()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
' numbers like "${lit}" can not start with `${ascii}` in ...${c.excerpt(num.pos)}...')
}
}
}
@ -273,7 +273,7 @@ fn (c Checker) check_boolean(b ast.Bool) ! {
return
}
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' boolean values like "$lit" can only be `true` or `false` literals, not `$lit` in ...${c.excerpt(b.pos)}...')
' boolean values like "${lit}" can only be `true` or `false` literals, not `${lit}` in ...${c.excerpt(b.pos)}...')
}
// check_date_time returns an error if `dt` is not a valid TOML date-time string (RFC 3339).
@ -296,7 +296,7 @@ fn (c Checker) check_date_time(dt ast.DateTime) ! {
// Validate the split into date and time parts.
if split.len != 2 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" contains too many date/time separators in ...${c.excerpt(dt.pos)}...')
' "${lit}" contains too many date/time separators in ...${c.excerpt(dt.pos)}...')
}
// Re-use date and time validation code for detailed testing of each part
c.check_date(ast.Date{
@ -320,11 +320,11 @@ fn (c Checker) check_date_time(dt ast.DateTime) ! {
// Use V's builtin functionality to validate the string
time.parse_rfc3339(lit) or {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Date-Time format string "$err". In ...${c.excerpt(dt.pos)}...')
' "${lit}" is not a valid RFC 3339 Date-Time format string "${err}". In ...${c.excerpt(dt.pos)}...')
}
} else {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Date-Time format string in ...${c.excerpt(dt.pos)}...')
' "${lit}" is not a valid RFC 3339 Date-Time format string in ...${c.excerpt(dt.pos)}...')
}
}
@ -334,27 +334,27 @@ fn (c Checker) check_date(date ast.Date) ! {
parts := lit.split('-')
if parts.len != 3 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Date format string in ...${c.excerpt(date.pos)}...')
' "${lit}" is not a valid RFC 3339 Date format string in ...${c.excerpt(date.pos)}...')
}
yyyy := parts[0]
if yyyy.len != 4 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" does not have a valid RFC 3339 year indication in ...${c.excerpt(date.pos)}...')
' "${lit}" does not have a valid RFC 3339 year indication in ...${c.excerpt(date.pos)}...')
}
mm := parts[1]
if mm.len != 2 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" does not have a valid RFC 3339 month indication in ...${c.excerpt(date.pos)}...')
' "${lit}" does not have a valid RFC 3339 month indication in ...${c.excerpt(date.pos)}...')
}
dd := parts[2]
if dd.len != 2 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" does not have a valid RFC 3339 day indication in ...${c.excerpt(date.pos)}...')
' "${lit}" does not have a valid RFC 3339 day indication in ...${c.excerpt(date.pos)}...')
}
// Use V's builtin functionality to validate the string
time.parse_rfc3339(lit) or {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Date format string "$err". In ...${c.excerpt(date.pos)}...')
' "${lit}" is not a valid RFC 3339 Date format string "${err}". In ...${c.excerpt(date.pos)}...')
}
}
@ -374,15 +374,15 @@ fn (c Checker) check_time(t ast.Time) ! {
starts_with_zero := hhmmss.starts_with('0')
if !starts_with_zero {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" must be zero prefixed in ...${c.excerpt(t.pos)}...')
' "${lit}" must be zero prefixed in ...${c.excerpt(t.pos)}...')
}
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Time format string in ...${c.excerpt(t.pos)}...')
' "${lit}" is not a valid RFC 3339 Time format string in ...${c.excerpt(t.pos)}...')
}
// Use V's builtin functionality to validate the time string
time.parse_rfc3339(parts[0]) or {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' "$lit" is not a valid RFC 3339 Time format string "$err". In ...${c.excerpt(t.pos)}...')
' "${lit}" is not a valid RFC 3339 Time format string "${err}". In ...${c.excerpt(t.pos)}...')
}
}
@ -393,7 +393,7 @@ pub fn (c Checker) check_quoted(q ast.Quoted) ! {
triple_quote := quote + quote + quote
if q.is_multiline && lit.ends_with(triple_quote) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' string values like "$lit" has unbalanced quote literals `q.quote` in ...${c.excerpt(q.pos)}...')
' string values like "${lit}" has unbalanced quote literals `q.quote` in ...${c.excerpt(q.pos)}...')
}
c.check_quoted_escapes(q)!
c.check_utf8_validity(q)!
@ -441,7 +441,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
if !contains_newlines {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' can not escape whitespaces in multi-line strings (`\\ `) at `$escape` ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
' can not escape whitespaces in multi-line strings (`\\ `) at `${escape}` (${st.line_nr},${st.col}) in ...${c.excerpt(q.pos)}...')
}
// Rest of line must only be space chars from this point on
for {
@ -452,7 +452,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
if !(ch_ == ` ` || ch_ == `\t`) {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' invalid character `${u8(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
' invalid character `${u8(ch_).ascii_str()}` after `${escape}` at (${st.line_nr},${st.col}) in ...${c.excerpt(q.pos)}...')
}
}
}
@ -464,7 +464,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
if next_ch !in checker.allowed_basic_escape_chars {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' unknown basic string escape character `$next_ch.ascii_str()` in `$escape` ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
' unknown basic string escape character `${next_ch.ascii_str()}` in `${escape}` (${st.line_nr},${st.col}) in ...${c.excerpt(q.pos)}...')
}
}
// Check Unicode escapes
@ -477,14 +477,14 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
c.check_unicode_escape(s.text[pos..pos + 11]) or {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' escaped Unicode is invalid. $err.msg().capitalize() ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
' escaped Unicode is invalid. ${err.msg().capitalize()} (${st.line_nr},${st.col}) in ...${c.excerpt(q.pos)}...')
}
} else {
pos := s.state().pos
c.check_unicode_escape(s.text[pos..]) or {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' escaped Unicode is invalid. $err.msg().capitalize() ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
' escaped Unicode is invalid. ${err.msg().capitalize()} (${st.line_nr},${st.col}) in ...${c.excerpt(q.pos)}...')
}
}
}
@ -497,7 +497,7 @@ fn (c Checker) check_utf8_validity(q ast.Quoted) ! {
lit := q.text
if !utf8.validate_str(lit) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' the string value "$lit" is not valid UTF-8 in ...${c.excerpt(q.pos)}...')
' the string value "${lit}" is not valid UTF-8 in ...${c.excerpt(q.pos)}...')
}
}
@ -507,16 +507,16 @@ fn (c Checker) check_utf8_validity(q ast.Quoted) ! {
fn validate_utf8_codepoint_string(str string) ! {
int_val := strconv.parse_int(str, 16, 64) or { i64(-1) }
if int_val > checker.utf8_max || int_val < 0 {
return error('Unicode code point `$str` is outside the valid Unicode scalar value ranges.')
return error('Unicode code point `${str}` is outside the valid Unicode scalar value ranges.')
}
// Check if the Unicode value is actually in the valid Unicode scalar value ranges.
// TODO should probably be transferred / implemented in `utf8.validate(...)` also?
if !((int_val >= 0x0000 && int_val <= 0xD7FF) || (int_val >= 0xE000 && int_val <= 0x10FFFF)) {
return error('Unicode code point `$str` is not a valid Unicode scalar value.')
return error('Unicode code point `${str}` is not a valid Unicode scalar value.')
}
bytes := str.bytes()
if !utf8.validate(bytes.data, bytes.len) {
return error('Unicode code point `$str` is not a valid UTF-8 code point.')
return error('Unicode code point `${str}` is not a valid UTF-8 code point.')
}
}
@ -526,13 +526,13 @@ fn validate_utf8_codepoint_string(str string) ! {
fn (c Checker) check_unicode_escape(esc_unicode string) ! {
if esc_unicode.len < 5 || !esc_unicode.to_lower().starts_with('u') {
// Makes sure the input to this function is actually valid.
return error('`$esc_unicode` is not a valid escaped Unicode sequence.')
return error('`${esc_unicode}` is not a valid escaped Unicode sequence.')
}
is_long_esc_type := esc_unicode.starts_with('U')
mut sequence := esc_unicode[1..]
hex_digits_len := if is_long_esc_type { 8 } else { 4 }
if sequence.len < hex_digits_len {
return error('Unicode escape sequence `$esc_unicode` should be at least $hex_digits_len in length.')
return error('Unicode escape sequence `${esc_unicode}` should be at least ${hex_digits_len} in length.')
}
sequence = sequence[..hex_digits_len]
// TODO not enforced in BurnSushi testsuite??
@ -563,19 +563,19 @@ pub fn (c Checker) check_comment(comment ast.Comment) ! {
if ch_byte == 0x0D {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' carrige return character `$ch_byte.hex()` is not allowed in comments ($st.line_nr,$st.col).')
' carrige return character `${ch_byte.hex()}` is not allowed in comments (${st.line_nr},${st.col}).')
}
// Check for control characters (allow TAB)
if util.is_illegal_ascii_control_character(ch_byte) {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' control character `$ch_byte.hex()` is not allowed ($st.line_nr,$st.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...')
' control character `${ch_byte.hex()}` is not allowed (${st.line_nr},${st.col}) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...')
}
}
// Check for bad UTF-8 encoding
if !utf8.validate_str(lit) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' comment "$lit" is not valid UTF-8 in ...${c.excerpt(comment.pos)}...')
' comment "${lit}" is not valid UTF-8 in ...${c.excerpt(comment.pos)}...')
}
}