Skip to content

Commit f50f409

Browse files
authored
toml: simplify bool keys in scanner and parser (#12625)
1 parent 1b691e7 commit f50f409

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

vlib/toml/parser/parser.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ pub fn (mut p Parser) root_table() ? {
463463
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping formatting "$p.tok.kind" "$p.tok.lit"')
464464
continue
465465
}
466-
.bare, .quoted, .boolean, .number, .minus, .underscore { // NOTE .boolean allows for use of "true" and "false" as table keys
466+
.bare, .quoted, .number, .minus, .underscore {
467467
// Peek forward as far as we can skipping over space formatting tokens.
468468
peek_tok, _ := p.peek_over(1, parser.keys_and_space_formatting) ?
469469

@@ -652,7 +652,7 @@ pub fn (mut p Parser) table_contents(mut tbl map[string]ast.Value) ? {
652652
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping formatting "$p.tok.kind" "$p.tok.lit"')
653653
continue
654654
}
655-
.bare, .quoted, .boolean, .number, .minus, .underscore { // NOTE .boolean allows for use of "true" and "false" as table keys
655+
.bare, .quoted, .number, .minus, .underscore {
656656
// Peek forward as far as we can skipping over space formatting tokens.
657657
peek_tok, _ := p.peek_over(1, parser.keys_and_space_formatting) ?
658658

@@ -735,7 +735,7 @@ pub fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) ? {
735735
// '}' bracket
736736
return
737737
}
738-
.bare, .quoted, .boolean, .number, .minus, .underscore {
738+
.bare, .quoted, .number, .minus, .underscore {
739739
// Peek forward as far as we can skipping over space formatting tokens.
740740
peek_tok, _ := p.peek_over(1, parser.space_formatting) ?
741741

@@ -836,7 +836,7 @@ pub fn (mut p Parser) array_of_tables_contents() ?[]ast.Value {
836836
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'parsing token "$p.tok.kind"')
837837

838838
match p.tok.kind {
839-
.bare, .quoted, .boolean, .number, .minus, .underscore {
839+
.bare, .quoted, .number, .minus, .underscore {
840840
// Peek forward as far as we can skipping over space formatting tokens.
841841
peek_tok, _ := p.peek_over(1, parser.space_formatting) ?
842842

@@ -972,7 +972,7 @@ pub fn (mut p Parser) double_array_of_tables_contents(target_key DottedKey) ?[]a
972972
}
973973

974974
match p.tok.kind {
975-
.bare, .quoted, .boolean, .number, .minus, .underscore {
975+
.bare, .quoted, .number, .minus, .underscore {
976976
// Peek forward as far as we can skipping over space formatting tokens.
977977
peek_tok, _ = p.peek_over(1, parser.space_formatting) ?
978978

vlib/toml/scanner/scanner.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ pub fn (mut s Scanner) scan() ?token.Token {
125125

126126
if util.is_key_char(byte_c) {
127127
key := s.extract_key()
128-
key_lower_case := key.to_lower()
129-
if key_lower_case == 'true' || key_lower_case == 'false' {
128+
if !s.is_left_of_assign && (key == 'true' || key == 'false') {
130129
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'identified a boolean "$key" ($key.len)')
131130
return s.new_token(.boolean, key, key.len)
132131
}

0 commit comments

Comments
 (0)