Decode
#func Decode(text: str): Throws<value.Value>Turns TOML into a Value. On invalid text it throws an Error with the kind, a toml.* code and the line and column of the mistake.
import encoding.toml
import encoding.value
func main throw:
text := "title = \"salam\"\n\n[server]\nhost = \"localhost\"\nport = 8080\ntags = [\"a\", \"b\"]\n"
println toml.Valid(text), toml.Valid("= no key")
v := try toml.Decode(text)
server := value.ObjectGet(v, "server")
println value.AsString(value.ObjectGet(v, "title")),
value.AsInt(value.ObjectGet(server, "port"))
print try toml.Encode(v)
try:
toml.Decode("a = 1\nb = \n")
catch e:
println e.KindName(), e.line, e.column, e.code
end
try:
println toml.Encode(value.ValueInt(1))
catch e:
println e.ToStr()
end
endtrue false salam 8080 title = "salam" [server] host = "localhost" port = 8080 tags = ["a", "b"] syntax error 2 5 toml.expected_value toml: the top level must be an object, since a TOML document is a table, not an integer