marzer / tomlplusplus

Header-only TOML config file parser and serializer for C++17.
https://marzer.github.io/tomlplusplus/
MIT License
1.53k stars 146 forks source link

Table source is wrong by one symbol #152

Closed vaartis closed 2 years ago

vaartis commented 2 years ago

Environment

toml++ version and/or commit hash: both 3.1.0 and e55ac0288f2bcf0b8cc5ad56a75398c017198aad, does not happen on 2.5.0.

Compiler: Clang 13

C++ standard mode: 20

Target arch: x64

Library configuration overrides: N/A

Relevant compilation flags: N/A

Describe the bug

When getting a source of a toml::table, the begin.column is one symbol off, i.e. if the table starts at (line,column) 1,1 the source says it's one (1,2).

Steps to reproduce (or a small repro code sample)

toml.cpp

toml::table parsed_root = toml::parse_file("assets.toml");
if (parsed_root["shaders"]) {
      auto source = parsed_root["shaders"].node()->source().begin;
      spdlog::info("{} {}", source.line, source.column);
}

assets.toml

[shaders.room_darker]
file = "room_darker.frag"
args = { n = "integer", ambientLightLevel = "float" }

Expected output: 1 1 Actual output: 1 2

Additional information

marzer commented 2 years ago

Thanks for the report. Will take a look over the weekend :)

marzer commented 2 years ago

Well this turned out to be pretty easy. It wasn't all tables, only specifically the cases where a [dotted.table] would cause an implcit parent table to be generated - in your example, "shaders" was incorrectly recorded at (1,2) but "shaders.room_darker" was correctly recorded at (1,1). A dumb copy+paste bug left over from an earlier refactor.

Thanks for the report!

vaartis commented 2 years ago

Just checked and the issue is indeed fixed, thank you.