Fix Config.skipChildBlock()
Before, there would be issues for nested child blocks
This commit is contained in:
parent
43e3d268c9
commit
c4d2c40f1a
1 changed files with 13 additions and 5 deletions
|
|
@ -139,9 +139,7 @@ fn load(config: *Config, reader: *Io.Reader) !void {
|
|||
try config.skipChildBlock(&parser);
|
||||
}
|
||||
},
|
||||
.child_block_end => {
|
||||
@panic("Reached end of non-existant child block. A bug in zig-kdl?");
|
||||
},
|
||||
.child_block_end => log.err("Reached unexpected .child_block_end. Ignoring it", .{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -198,11 +196,21 @@ fn loadBordersChildBlock(config: *Config, parser: *kdl.Parser) !void {
|
|||
/// Skips an entire child block in KDL
|
||||
fn skipChildBlock(_: *Config, parser: *kdl.Parser) !void {
|
||||
log.warn("Unexpected child block. Skipping it", .{});
|
||||
|
||||
var depth: usize = 0;
|
||||
while (try parser.next()) |event| {
|
||||
switch (event) {
|
||||
.child_block_end => return,
|
||||
// Nested child block
|
||||
.child_block_begin => depth += 1,
|
||||
.child_block_end => {
|
||||
if (depth == 0) {
|
||||
return;
|
||||
} else {
|
||||
depth -= 1;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
// We don't care about anything else in this child block
|
||||
// We don't care about any nodes in here
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue