Skip to content

Track source document name per datum#36

Merged
cktan merged 1 commit into
cktan:mainfrom
dutow:feat/source-name-tracking
Jun 18, 2026
Merged

Track source document name per datum#36
cktan merged 1 commit into
cktan:mainfrom
dutow:feat/source-name-tracking

Conversation

@dutow

@dutow dutow commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

5589b29 introduced toml_merge, and 91ee2f1 introduced line number tracking, but the two doesn't work properly together: the merge copies the line numbers, but we lose track of the original file.

A typical use case would be using merge to handle multiple configuration files (e.g. incude/conf.d/...), and the source information (line numbers) to provide error messages to the users. With only the line number, this doesn't work out as we can't tell which file contains the error.

--

Add a per-datum source field to toml_datum_t recording which document each value came from, alongside the existing lineno/colno.

  • New toml_parse_named() and toml_parse_file_named() accept a source name (e.g. a filename); toml_parse()/toml_parse_file() delegate with NULL, and toml_parse_file_ex() uses the file path automatically.
  • The name is copied once into the result pool and stamped on every datum via a recursive walk after parsing; NULL when no name is given.
  • toml_merge() preserves each entry's origin, interning (deduplicating) source names into the merged pool. Table key strings are now also copied into the merged pool so the merged result is independent of its inputs.
  • Document the new field and functions in API.md/README.md; add test/source.

@cktan

cktan commented Jun 17, 2026 via email

Copy link
Copy Markdown
Owner

@dutow

dutow commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

That would also make it consistent, but I think that (and the current version) significantly limits the usability of the function. If somebody wants to write a user friendly application, it has to provide information about the error context to users.

Right now I just duplicated merge in my own code with these changes, I can continue to do so, but I thought it could be useful for others too.

@cktan

cktan commented Jun 18, 2026

Copy link
Copy Markdown
Owner

please rebase and i will merge it.

Add a per-datum `source` field to toml_datum_t recording which document
each value came from, alongside the existing lineno/colno.

- New toml_parse_named() and toml_parse_file_named() accept a source name
  (e.g. a filename); toml_parse()/toml_parse_file() delegate with NULL, and
  toml_parse_file_ex() uses the file path automatically.
- The name is copied once into the result pool and stamped on every datum
  via a recursive walk after parsing; NULL when no name is given.
- toml_merge() preserves each entry's origin, interning (deduplicating)
  source names into the merged pool. Table key strings are now also copied
  into the merged pool so the merged result is independent of its inputs.
- Document the new field and functions in API.md/README.md; add test/source.
@dutow dutow force-pushed the feat/source-name-tracking branch from ba7baa9 to ef88aea Compare June 18, 2026 13:55
@cktan cktan merged commit 66b6b9d into cktan:main Jun 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants