Repository navigation
feat: the TOML reader accepts TOML 1.1 inline tables written over several lines - #929
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
…eral lines
mcpp.libs.toml read an inline table only when it was written on one line:
a newline, a comment or a comma after the last pair inside the braces was
refused with `expected key`. TOML 1.1.0 allows all three, and the provider
example in docs/35 already writes `runner = { ... }` over three lines, which
mcpp could not read.
read_inline_table now skips newlines and comments between the braces and the
pairs and accepts a comma after the last pair. A pair stays on one line, an
empty element (`{ , }`, `{ a = 1,, }`) is still refused, and a table that
never closes is reported at its `{` as `unterminated inline table`. Every
document that parsed before parses into the same tree.
Two text editors meet the new form:
- upsert_dependency_text (`mcpp add`, template self-dependency injection)
replaced an existing entry by its first line only, so its own re-parse
refused the result. It now replaces the whole value.
- `mcpp remove` erased the first line only and wrote the file without a
re-parse, leaving the rest of the value as a corrupt manifest. It now erases
the whole value.
Both use one helper, mcpp::manifest::assignment_end, which finds the newline
after a value by counting brackets outside strings and comments.
`mcpp index pin` and `unpin` still edit only an entry on one line; their
refusal of a multi-line one now says so instead of calling it malformed.
Docs: docs/04 states the TOML dialect, docs/09 the pin/unpin boundary, in
English and Chinese.
Tests: Toml.AnInlineTableSpansLines, Toml.AnInlineTableKeepsEachPairOnOneLine,
ManifestEditor.ReplacesAnEntryWrittenOverSeveralLines,
ManifestEditor.AnAssignmentEndsWhereItsValueCloses, and a multi-line entry in
e2e 23_remove_update.sh.
Closes mcpp-community#928.
This branch has not been deployed
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.
Summary
mcpp.libs.tomlread an inline table only when it was written on one line. A newline, a comment or a comma after the last pair inside the braces was refused withexpected key. TOML 1.1.0 allows all three, and the provider example indocs/35-platforms.mdalready writesrunner = { ... }over three lines, which mcpp could not read. The released 2026.11.12.1 refusescmdline = { version = "0.0.1",⏎ features = [] }withmcpp.toml:6:31: error: expected key.read_inline_tablenow skips newlines and comments between the braces and the pairs, and accepts a comma after the last pair. A pair stays on one line (key = value, as TOML 1.1 requires). An empty element ({ , },{ a = 1,, }) is still refused. A table that never closes is reported at its{asunterminated inline table.Two text editors meet the new form, and both now handle the whole value:
upsert_dependency_text(mcpp add, template self-dependency injection) replaced an existing entry by its first line only. Its own re-parse then refused the result (dependency edit produced invalid manifest).mcpp removeerased the first line only and wrote the file without a re-parse. That left the rest of the value behind as a corrupt manifest.Both use one helper,
mcpp::manifest::assignment_end. It finds the newline after a value by counting brackets outside strings and comments.mcpp index pinandunpinstill edit only an[indices]entry written on one line. They already refused a multi-line one without writing anything, but called it "malformed"; the refusal now states the real cause.docs/04states the TOML dialect anddocs/09states the pin/unpin boundary, in English and Chinese.Closes #928.
Criteria
Toml.AnInlineTableSpansLinescovers newlines, comments, a trailing comma, a nested table with trailing commas, a multi-line array inside the table,{⏎}, and a key after the table.Toml.AnInlineTableKeepsEachPairOnOneLinecovers what stays refused: a pair split before or after=, two pairs without a comma,,,,{ , }, and the position and text ofunterminated inline table. On macOS arm64 I builtmodules/libswithtests/unit/test_toml.cppusing the released 2026.11.12.1. Both cases fail without the change (expected key, and"expected key" == "unterminated inline table") and pass with it; all 20 cases pass.ManifestEditor.ReplacesAnEntryWrittenOverSeveralLinesreplaces a multi-line entry that holds a}in a comment and a]in a string.ManifestEditor.AnAssignmentEndsWhereItsValueClosespins the helper. On the same host I built themodules/manifestpackage alone with these two tests, the two existingManifestEditortests andtests/unit/test_toml_serialize.cpp(includingRepositoryManifestsRoundTrip). All pass. Without the change, the editor case fails withdependency edit produced invalid manifest: mcpp.toml:7:23: error: expected key.tests/e2e/23_remove_update.shnow seeds a multi-linebaz = { ... }and removes it. With the released 2026.11.12.1 it fails: the manifest keeps the table's last three lines under[dependencies]. I did not build a full mcpp binary on this host, so the passing run of this script, and the compile ofsrc/pm/commands.cppmandsrc/pm/index_management.cppm, are left to CI. I checked themcpp removeerase logic separately in a scratch test that copies its lambda overassignment_end: on the script's manifest it leavesfooandbarintact.check_docs_style.sh,check_docs_structure.sh,check_version_pins.sh,check_manifest_key_classes.py,check_narrow_conversions.sh,check_include_regions.shandcheck_workflow_assertions.pypass.Intersections
serializewrites a document that reads back into the same tree (it writes inline tables on one line)TomlSerialize.*, includingRepositoryManifestsRoundTripmcpp addedits one entry and re-parses its resultManifestEditor.ReplacesAnEntryWrittenOverSeveralLinesmcpp removeerases one entry and leaves the others23_remove_update.sh(bazremoved whole,barkept)mcpp index pin/unpinedit an[indices]entry in place#inside a string is not a commentAnInlineTableSpansLines("{}"and"--"values),AnAssignmentEndsWhereItsValueClosesCompatibility
Every file that parsed before parses into the same tree. Files with an inline table over several lines, a comment inside one, or a trailing comma were refused before and now load. Only one error message changes for a file that was refused before: an inline table that never closes is reported at its
{asunterminated inline tableinstead ofexpected key. No output, default or cache key changes.Checks before merging
bash .github/tools/check_docs_style.sh,check_docs_structure.shandcheck_version_pins.shpass.python3 .github/tools/check_workflow_assertions.pypasses (a step asserts what its name says).git log origin/main..HEAD -i --grep='Co-Authored-By'prints nothing.compose one from the branch's commits. Suggested subject:
feat: the TOML reader accepts TOML 1.1 inline tables written over several lines.