Package Usage: go: github.com/creachadair/tomledit
Package tomledit allows structural edits of a TOML document.
To parse a TOML text into a Document, call Parse:
Once parsed, the structure of the Document is mutable, and changes to the
document will be reflected when it is written back out.
Note that the parser does not validate the semantics of the resulting
document. Issues such as duplicate keys, incorrect table order,
redefinitions, and so forth are not reported by the parser.
To write a Document back into TOML format, use a Formatter:
A Document consists of one or more sections: A "global" section at the
beginning of the input, with top-level key-value mappings that are not
captured in a named table; followed by zero or more sections denoting named
tables.
All sections except the global section have a Heading, which gives the name
of the section along with any documentation comments attached to it. The
contents of the section are represented as a slice of items, each of which
is a block of comments (concrete type parser.Comments) or a key-value
mapping (concrete type *parser.KeyValue). Modifying either of these fields
updates the structure of the section.
Each heading or key-value may have a block comment comment attached to
it. Block comments are attached to an item if they occur immediately before
it (with no intervening blanks); otherwise block comments stand alone as
their own items.
Headings and values may also have trailing line comments attached, if they
occur on the same line as the value. For example:
The comments attached to an item move with that item, and retain their
attachments when the document is formatted. To remove an attached comment,
set the corresponding field to a zero value.
Keys are denoted as slices of strings (parser.Key), representing the
dot-separated components of a TOML name (e.g., left.center.right). Use the
Equal and IsPrefixOf methods of a key to compare it to another key. It is
safe to construct key slices programmatically, or use parser.ParseKey.
Values are denoted as parser.Datum implementations. Primitive values
(parser.Token) are stored as uninterpreted text; this package does not
convert them into Go values (although you are free to do so). Otherwise, a
value is either an array (parser.Array) or an inline table (parser.Inline).
Values in key-value mappings are bound with an optional trailing line
comment, if one occurs on the same line as the value.
To construct values programmatically, use parser.ParseValue.
25 versions
Latest release: presque 2 ans ago
282 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/creachadair/tomledit