Lossless TOML 1.0 parsing and format-preserving configuration edits
let doc = @edit.parse("[workspace]\nmembers = ['core'] # keep\n")
let next = doc.append(["workspace", "members"], "'app'")
assert_eq(next.encode(), "[workspace]\nmembers = ['core','app'] # keep\n")| Operation | Behavior |
|---|---|
| parse, parse_bytes | Parse TOML 1.0, including dotted keys and arrays of tables. The byte boundary validates UTF-8 strictly. |
| encode, encode_bytes | Return the original or edited text, without normalization. |
| get | Read a value's original spelling in a standard or inline table. |
| set | Replace a value or insert a key into a standard or inline table. Existing implicit parent tables gain a header when necessary. Create missing intermediate tables with add_table. |
| remove | Remove a key, retaining surrounding comments and whitespace. |
| add_table | Append a standard table, quoting path segments as needed. |
| remove_table | Remove a table and its descendants, including sections interleaved with unrelated tables. |
| append, remove_item | Add or remove array items, retaining existing item text and comments. |
| element | Select an array-of-tables element by zero-based index. Select nested arrays from the enclosing element. |
| append_table | Append an element after the last element and its descendants, before an unrelated section. |
| TableElement methods | Read, set, insert and remove keys, edit ordinary arrays and standard subtables, or delete the selected element. Edits return the complete document. |
let doc = @edit.parse("[[projects]]\nname='One'\n[[projects]]\nname='Two'\n")
let changed = doc.element(["projects"], 1).set(["name"], "'Second'")
let appended = changed.append_table(["projects"], [(["name"], "'Third'")])
let removed = appended.element(["projects"], 0).delete()moon test -p finos/morphir-toml-edit finos/morphir-engine/config --target js --deny-warn
mise run test
mise run lint:moonbitpub struct Document {
// private fields
}fn Document::append(self : Document, path : Array[String], value : String) -> Document raise Diagnosticfn Document::element(self : Document, path : Array[String], index : Int) -> TableElement raise Diagnosticfn Document::remove_item(self : Document, path : Array[String], index : Int) -> Document raise Diagnosticpub struct TableElement {
// private fields
}fn TableElement::append(self : TableElement, path : Array[String], value : String) -> Document raise Diagnosticfn TableElement::append_table(self : TableElement, path : Array[String], entries : Array[(Array[String], String)]) -> Document raise Diagnosticfn TableElement::element(self : TableElement, path : Array[String], index : Int) -> TableElement raise Diagnosticfn TableElement::remove_item(self : TableElement, path : Array[String], index : Int) -> Document raise Diagnosticfn TableElement::remove_table(self : TableElement, path : Array[String]) -> Document raise Diagnosticfn TableElement::set(self : TableElement, path : Array[String], value : String) -> Document raise Diagnostic