Track source document name per datum#36
Merged
Merged
Conversation
Owner
|
I am leaning towards zeroing out the line number info for merged datums.
Too much work for something that very few people uses…
…On Wed, Jun 17, 2026 at 8:18 AM Zsolt Parragi ***@***.***> wrote:
5589b29
<5589b29>
introduced toml_merge, and 842ea36
<842ea36>
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.
------------------------------
You can view, comment on, or merge this pull request online at:
#36
Commit Summary
- ba7baa9
<ba7baa9>
Track source document name per datum
File Changes
(8 files <https://github.com/cktan/tomlc17/pull/36/files>)
- *M* API.md
<https://github.com/cktan/tomlc17/pull/36/files#diff-b161966f7254af9c9c5382e859495c69622843e4602a6bb4208e08134e660121>
(29)
- *M* README.md
<https://github.com/cktan/tomlc17/pull/36/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5>
(1)
- *M* src/tomlc17.c
<https://github.com/cktan/tomlc17/pull/36/files#diff-999eeab8d0157913bed077ac028dace55d03f01b5b065b4672af5490d887ec38>
(158)
- *M* src/tomlc17.h
<https://github.com/cktan/tomlc17/pull/36/files#diff-1f4dc2d648cf1c7cfd61da960c634741dedd25f639ec5f52e0e208707a2c2930>
(37)
- *M* test/Makefile
<https://github.com/cktan/tomlc17/pull/36/files#diff-740cb5a1689091cb894445e46683c255e39689ccba1c6c63d8a8841c8df8817d>
(2)
- *A* test/source/.gitignore
<https://github.com/cktan/tomlc17/pull/36/files#diff-d203a52205886e6f34a8af8c4187980d5c408b5c4b3c1d4945c7bd5603d47caf>
(1)
- *A* test/source/Makefile
<https://github.com/cktan/tomlc17/pull/36/files#diff-48cdafe31138bce3d19071b59e49bd96bdd21e4d3cb7a9795ec067fd37778cef>
(23)
- *A* test/source/test1.c
<https://github.com/cktan/tomlc17/pull/36/files#diff-c3b3042ff88374fa099a7b11ff28704edbb67a16de5b6c4eee611a3305e36da1>
(158)
Patch Links:
- https://github.com/cktan/tomlc17/pull/36.patch
- https://github.com/cktan/tomlc17/pull/36.diff
—
Reply to this email directly, view it on GitHub
<#36?email_source=notifications&email_token=AABDRFUYEUH6D72Q5N65TCT5AKZENA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF4ZTQOBUGY2DAMJQHGTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVRTG633UMVZF6Y3MNFRWW>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABDRFWHNFSBVH6LZFK3D7L5AKZENAVCNFSNUABFKJSXA33TNF2G64TZHM4TONJXHEZDKOJZHNEXG43VMU5TINRYGQ3DCMRSGUZKC5QC>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
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. |
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.
ba7baa9 to
ef88aea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
sourcefield to toml_datum_t recording which document each value came from, alongside the existing lineno/colno.