fmt: remove the prefixed module name of const names, that are in the same module (related #22183) (#22185)

This commit is contained in:
yuyi 2024-09-10 16:25:56 +08:00 committed by GitHub
parent 234fb8e2b0
commit 008aaad999
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
284 changed files with 2539 additions and 2572 deletions

View file

@ -462,7 +462,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
continue
}
}
if next_ch !in checker.allowed_basic_escape_chars {
if next_ch !in 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)}...')
@ -507,7 +507,7 @@ fn (c Checker) check_utf8_validity(q ast.Quoted) ! {
// Any preludes or prefixes like `0x` could pontentially yield wrong results.
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 {
if int_val > utf8_max || int_val < 0 {
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.

View file

@ -161,13 +161,13 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ! {
decoded_s += escape
continue
}
if unicode_val > decoder.utf8_max || unicode_val < 0 {
if unicode_val > utf8_max || unicode_val < 0 {
decoded_s += escape
continue
}
// Check if the Unicode value is actually in the valid Unicode scalar value ranges.
if !((unicode_val >= 0x0000 && unicode_val <= 0xD7FF)
|| (unicode_val >= 0xE000 && unicode_val <= decoder.utf8_max)) {
|| (unicode_val >= 0xE000 && unicode_val <= utf8_max)) {
decoded_s += escape
continue
}

View file

@ -186,7 +186,7 @@ fn (mut p Parser) check(check_token token.Kind) ! {
// and return an error if the next token is not one of [.cr, .nl, .hash, .eof].
fn (mut p Parser) peek_for_correct_line_ending_or_fail() ! {
// Disallow anything else than [.cr, .nl, .hash, .eof] after any space formatting.
peek_tok, _ := p.peek_over(1, parser.space_formatting)!
peek_tok, _ := p.peek_over(1, space_formatting)!
if peek_tok.kind !in [.cr, .nl, .hash, .eof] {
p.next()! // Forward to the peek_tok
return error(@MOD + '.' + @STRUCT + '.' + @FN +
@ -438,15 +438,15 @@ pub fn (mut p Parser) dotted_key() !DottedKey {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing dotted key...')
mut dotted_key := DottedKey([]string{})
key := p.key()!
p.ignore_while_peek(parser.space_formatting)
p.ignore_while_peek(space_formatting)
dotted_key << key.str()
for p.peek_tok.kind == .period {
p.next()! // .
p.check(.period)!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
next_key := p.key()!
dotted_key << next_key.text
p.ignore_while_peek(parser.space_formatting)
p.ignore_while_peek(space_formatting)
}
p.next()!
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsed dotted key `${dotted_key}` now at "${p.tok.kind}" "${p.tok.lit}"')
@ -478,7 +478,7 @@ pub fn (mut p Parser) root_table() ! {
}
.bare, .quoted, .number, .minus, .underscore {
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ := p.peek_over(1, parser.keys_and_space_formatting)!
peek_tok, _ := p.peek_over(1, keys_and_space_formatting)!
if peek_tok.kind == .period {
dotted_key, val := p.dotted_key_value()!
@ -522,7 +522,7 @@ pub fn (mut p Parser) root_table() ! {
t[key.str()] = val
}
} else {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
key, val := p.key_value()!
t := p.find_table()!
@ -543,8 +543,8 @@ pub fn (mut p Parser) root_table() ! {
mut peek_tok := p.peek_tok
// Disallow `[ [table]]`
if p.tok.kind in parser.space_formatting {
peek_tok, _ = p.peek_over(1, parser.space_formatting)!
if p.tok.kind in space_formatting {
peek_tok, _ = p.peek_over(1, space_formatting)!
if peek_tok.kind == .lsbr {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' unexpected "${p.tok.kind}" "${p.tok.lit}" at this (excerpt): "...${p.excerpt()}..."')
@ -552,10 +552,10 @@ pub fn (mut p Parser) root_table() ! {
}
// Allow `[ d.e.f]`
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ = p.peek_over(1, parser.keys_and_space_formatting)!
peek_tok, _ = p.peek_over(1, keys_and_space_formatting)!
if p.tok.kind == .lsbr {
// Parse `[[table]]`
@ -581,7 +581,7 @@ pub fn (mut p Parser) root_table() ! {
// Disallow re-declaring the key
p.check_explicitly_declared_array_of_tables(dotted_key)!
p.check(.rsbr)!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
arr := p.find_array_of_tables()!
if val := arr[p.last_aot_index] {
if val is map[string]ast.Value {
@ -618,7 +618,7 @@ pub fn (mut p Parser) root_table() ! {
// ... also check implicitly declared keys
p.check_implicitly_declared(dotted_key)!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'setting root map key to `${dotted_key}` at "${p.tok.kind}" "${p.tok.lit}"')
p.root_map_key = dotted_key
@ -643,7 +643,7 @@ pub fn (mut p Parser) root_table() ! {
}
// Allow [ key ]
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'setting root map key to `${dotted_key}` at "${p.tok.kind}" "${p.tok.lit}"')
p.root_map_key = dotted_key
@ -697,7 +697,7 @@ pub fn (mut p Parser) table_contents(mut tbl map[string]ast.Value) ! {
}
.bare, .quoted, .number, .minus, .underscore {
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ := p.peek_over(1, parser.keys_and_space_formatting)!
peek_tok, _ := p.peek_over(1, keys_and_space_formatting)!
if peek_tok.kind == .period {
dotted_key, val := p.dotted_key_value()!
@ -710,7 +710,7 @@ pub fn (mut p Parser) table_contents(mut tbl map[string]ast.Value) ! {
t[key.str()] = val
}
} else {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
key, val := p.key_value()!
unsafe {
@ -747,7 +747,7 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ! {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing token "${p.tok.kind}"')
if previous_token_was_value {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
if p.tok.kind != .rcbr {
p.expect(.comma)!
}
@ -765,7 +765,7 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ! {
continue
}
.comma {
p.ignore_while_peek(parser.space_formatting)
p.ignore_while_peek(space_formatting)
if p.peek_tok.kind in [.comma, .rcbr] {
p.next()! // Forward to the peek_tok
return error(@MOD + '.' + @STRUCT + '.' + @FN +
@ -780,7 +780,7 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ! {
}
.bare, .quoted, .number, .minus, .underscore {
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ := p.peek_over(1, parser.space_formatting)!
peek_tok, _ := p.peek_over(1, space_formatting)!
if peek_tok.kind == .period {
dotted_key, val := p.dotted_key_value()!
@ -793,7 +793,7 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ! {
t[key.str()] = val
}
} else {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
key, val := p.key_value()!
key_str := key.str()
if _ := tbl[key_str] {
@ -824,9 +824,9 @@ pub fn (mut p Parser) array_of_tables(mut table map[string]ast.Value) ! {
p.check(.lsbr)! // '[' bracket
// Allow [[ key]]
p.ignore_while(parser.space_formatting)
peek_tok, _ := p.peek_over(1, parser.space_formatting)!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
peek_tok, _ := p.peek_over(1, space_formatting)!
p.ignore_while(space_formatting)
// [[key.key]] horror
if peek_tok.kind == .period {
@ -838,13 +838,13 @@ pub fn (mut p Parser) array_of_tables(mut table map[string]ast.Value) ! {
p.next()!
// Allow [[key ]]
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
p.check(.rsbr)!
p.peek_for_correct_line_ending_or_fail()!
p.expect(.rsbr)!
p.ignore_while(parser.all_formatting)
p.ignore_while(all_formatting)
dotted_key := DottedKey([key.str()])
dotted_key_str := dotted_key.str()
@ -893,12 +893,12 @@ pub fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) ! {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing nested array of tables "${p.tok.kind}" "${p.tok.lit}"')
dotted_key := p.dotted_key()!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
p.check(.rsbr)!
p.expect(.rsbr)!
p.ignore_while(parser.all_formatting)
p.ignore_while(all_formatting)
if dotted_key.len != 2 {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
@ -988,13 +988,13 @@ pub fn (mut p Parser) double_array_of_tables_contents(target_key DottedKey) ![]a
for p.tok.kind != .eof {
p.next()!
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing token "${p.tok.kind}"')
p.ignore_while(parser.all_formatting)
p.ignore_while(all_formatting)
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, peeked_over = p.peek_over(1, parser.space_formatting)!
peek_tok, peeked_over = p.peek_over(1, space_formatting)!
// Peek for occurrence of `[[`
if peek_tok.kind == .lsbr {
peek_tok, peeked_over = p.peek_over(peeked_over + 1, parser.space_formatting)!
peek_tok, peeked_over = p.peek_over(peeked_over + 1, space_formatting)!
if peek_tok.kind == .lsbr {
mut arr := []ast.Value{}
arr << tbl
@ -1005,7 +1005,7 @@ pub fn (mut p Parser) double_array_of_tables_contents(target_key DottedKey) ![]a
match p.tok.kind {
.bare, .quoted, .number, .minus, .underscore {
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ = p.peek_over(1, parser.space_formatting)!
peek_tok, _ = p.peek_over(1, space_formatting)!
if peek_tok.kind == .period {
mut dotted_key, val := p.dotted_key_value()!
@ -1038,20 +1038,20 @@ pub fn (mut p Parser) double_array_of_tables_contents(target_key DottedKey) ![]a
peek_tok = p.peek_tok
// Allow `[ d.e.f]`
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
// Peek forward as far as we can skipping over space formatting tokens.
peek_tok, _ = p.peek_over(1, parser.space_formatting)!
peek_tok, _ = p.peek_over(1, space_formatting)!
if peek_tok.kind == .period {
// Parse `[d.e.f]`
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
dotted_key := p.dotted_key()!
implicit_allocation_key = dotted_key
if dotted_key.len > 2 {
implicit_allocation_key = dotted_key[2..]
}
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'keys are: dotted `${dotted_key}`, target `${target_key}`, implicit `${implicit_allocation_key}` at "${p.tok.kind}" "${p.tok.lit}"')
p.expect(.rsbr)!
p.peek_for_correct_line_ending_or_fail()!
@ -1084,7 +1084,7 @@ pub fn (mut p Parser) array() ![]ast.Value {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing token "${p.tok.kind}" "${p.tok.lit}"')
if previous_token_was_value {
p.ignore_while(parser.all_formatting)
p.ignore_while(all_formatting)
if p.tok.kind != .rsbr && p.tok.kind != .hash {
p.expect(.comma)!
}
@ -1097,7 +1097,7 @@ pub fn (mut p Parser) array() ![]ast.Value {
previous_token_was_value = true
}
.comma {
p.ignore_while_peek(parser.space_formatting)
p.ignore_while_peek(space_formatting)
// Trailing commas before array close is allowed
// so we do not do `if p.peek_tok.kind == .rsbr { ... }`
@ -1120,7 +1120,7 @@ pub fn (mut p Parser) array() ![]ast.Value {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping comment "${c.text}"')
}
.lcbr {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
mut t := map[string]ast.Value{}
p.inline_table(mut t)!
arr << ast.Value(t)
@ -1178,7 +1178,7 @@ pub fn (mut p Parser) key() !ast.Key {
pos := p.tok.pos()
for p.peek_tok.kind != .assign && p.peek_tok.kind != .period && p.peek_tok.kind != .rsbr {
p.next()!
if p.tok.kind !in parser.space_formatting {
if p.tok.kind !in space_formatting {
lits += p.tok.lit
}
}
@ -1246,9 +1246,9 @@ pub fn (mut p Parser) key_value() !(ast.Key, ast.Value) {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing key value pair...')
key := p.key()!
p.next()!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
p.check(.assign)! // Assignment operator
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
value := p.value()!
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsed key value pair. `${key} = ${value}`')
@ -1263,11 +1263,11 @@ pub fn (mut p Parser) key_value() !(ast.Key, ast.Value) {
// see also `key()` and `value()`
pub fn (mut p Parser) dotted_key_value() !(DottedKey, ast.Value) {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing dotted key value pair...')
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
dotted_key := p.dotted_key()!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
p.check(.assign)!
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
value := p.value()!
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsed dotted key value pair `${dotted_key} = ${value}`...')
@ -1297,7 +1297,7 @@ pub fn (mut p Parser) value() !ast.Value {
ast.Value(p.array()!)
}
.lcbr {
p.ignore_while(parser.space_formatting)
p.ignore_while(space_formatting)
mut t := map[string]ast.Value{}
p.inline_table(mut t)!
ast.Value(t)
@ -1341,7 +1341,7 @@ pub fn (mut p Parser) bare() !ast.Bare {
mut lits := p.tok.lit
pos := p.tok.pos()
for p.peek_tok.kind != .assign && p.peek_tok.kind != .period && p.peek_tok.kind != .rsbr
&& p.peek_tok.kind !in parser.space_formatting {
&& p.peek_tok.kind !in space_formatting {
p.next()!
if p.tok.kind == .bare || p.tok.kind == .minus || p.tok.kind == .underscore {
lits += p.tok.lit

View file

@ -99,7 +99,7 @@ pub fn (mut s Scanner) scan() !token.Token {
for {
c := s.next()
byte_c := u8(c)
if c == scanner.end_of_text {
if c == end_of_text {
s.inc_line_number()
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'reached EOF')
return s.new_token(.eof, '', 1)
@ -268,7 +268,7 @@ pub fn (mut s Scanner) next() u32 {
c := s.text[opos]
return c
}
return scanner.end_of_text
return end_of_text
}
// skip skips one character ahead.
@ -300,7 +300,7 @@ pub fn (s &Scanner) at() u32 {
if s.pos < s.text.len {
return s.text[s.pos]
}
return scanner.end_of_text
return end_of_text
}
// at_crlf returns `true` if the scanner is at a `\r` character
@ -321,7 +321,7 @@ pub fn (s &Scanner) peek(n int) u32 {
}
return s.text[s.pos + n]
}
return scanner.end_of_text
return end_of_text
}
// reset resets the internal state of the scanner.
@ -355,7 +355,7 @@ fn (mut s Scanner) new_token(kind token.Kind, lit string, len int) token.Token {
fn (mut s Scanner) ignore_line() !string {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, ' ignoring until EOL...')
start := s.pos
for c := s.at(); c != scanner.end_of_text && c != `\n`; c = s.at() {
for c := s.at(); c != end_of_text && c != `\n`; c = s.at() {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping "${u8(c).ascii_str()} / ${c}"')
if s.at_crlf() {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'letting `\\r\\n` slip through')
@ -510,7 +510,7 @@ fn (mut s Scanner) extract_multiline_string() !string {
if c == quote {
if s.peek(1) == quote && s.peek(2) == quote {
if s.peek(3) == scanner.end_of_text {
if s.peek(3) == end_of_text {
s.pos += 3
s.col += 3
lit += quote.ascii_str() + quote.ascii_str() + quote.ascii_str()
@ -593,7 +593,7 @@ fn (mut s Scanner) extract_number() !string {
mut float_precision := 0
if c == `.` {
mut i := 1
for c_ := u8(s.peek(i)); c_ != scanner.end_of_text && c_ != `\n`; c_ = u8(s.peek(i)) {
for c_ := u8(s.peek(i)); c_ != end_of_text && c_ != `\n`; c_ = u8(s.peek(i)) {
if !c_.is_digit() && c_ != `,` {
float_precision = 0
break
@ -610,7 +610,7 @@ fn (mut s Scanner) extract_number() !string {
s.col += 2
}
c = s.at()
if !(u8(c).is_hex_digit() || c in scanner.digit_extras) || (c == `.` && s.is_left_of_assign) {
if !(u8(c).is_hex_digit() || c in digit_extras) || (c == `.` && s.is_left_of_assign) {
break
}
s.pos++

View file

@ -414,7 +414,7 @@ pub fn (d Doc) reflect[T]() T {
// quoted keys are supported as `a."b.c"` or `a.'b.c'`.
// Arrays can be queried with `a[0].b[1].[2]`.
pub fn (d Doc) value(key string) Any {
key_split := parse_dotted_key(key) or { return toml.null }
key_split := parse_dotted_key(key) or { return null }
return d.value_(d.ast.table, key_split)
}
@ -434,21 +434,21 @@ pub fn (d Doc) value_opt(key string) !Any {
// value_ returns the value found at `key` in the map `values` as `Any` type.
fn (d Doc) value_(value ast.Value, key []string) Any {
if key.len == 0 {
return toml.null
return null
}
mut ast_value := ast.Value(ast.Null{})
k, index := parse_array_key(key[0])
if k == '' {
a := value as []ast.Value
ast_value = a[index] or { return toml.null }
ast_value = a[index] or { return null }
}
if value is map[string]ast.Value {
ast_value = value[k] or { return toml.null }
ast_value = value[k] or { return null }
if index > -1 {
a := ast_value as []ast.Value
ast_value = a[index] or { return toml.null }
ast_value = a[index] or { return null }
}
}
@ -526,11 +526,11 @@ pub fn ast_to_any(value ast.Value) Any {
return aa
}
else {
return toml.null
return null
}
}
return toml.null
return null
// TODO: decide this
// panic(@MOD + '.' + @STRUCT + '.' + @FN + ' can\'t convert "$value"')
// return Any('')