TomlParser

Usage

use TOML.TomlParser;

or

import TOML.TomlParser;

Parser module with the Toml class for the Chapel TOML library.

config const debugTomlParser = false

Prints a line by line output of parsing process

class Toml : writeSerializable

Class to hold various types parsed from input used to recursively hold tables and respective values

proc init()
proc init(s: string)
proc init(A: [?D] shared Toml)  where D.isAssociative()
proc init(ld: date)
proc init(ti: time)
proc init(dt: dateTime)
proc init(i: int)
proc init(boo: bool)
proc init(re: real)
proc init(arr: [?dom] shared Toml)  where !dom.isAssociative()
proc init(lst: list(shared Toml))
proc init(root: Toml)
proc this(tblpath: string) ref : shared Toml? throws

Returns the table element at the given table path.

Since this method throws if the table path does not exist, it cannot be used to assign new values to new table paths. For that, use set.

assert(myToml.pathExists("A"));
myToml["A"] = ...; // OK, since "A" exists already
myToml["B"] = ...; // ERROR, since "B" does not exist
myToml.set("B", ...); // OK, since `set` creates "B"
Throws:

TomlError – If the table path does not exist.

proc get(tblpath: string, const in default: shared Toml? = nil: shared Toml?) : shared Toml?

Returns the table element at the given table path, or the default value if not found.

proc set(tbl: string, toml: Toml) throws

Set the table element at the given table path to the given value.

Throws:

TomlError – If the parent table path does not exist. For example, setting “a.b” when “a” does not exist will throw an error.

proc set(tbl: string, s: string) throws
proc set(tbl: string, i: int) throws
proc set(tbl: string, b: bool) throws
proc set(tbl: string, r: real) throws
proc set(tbl: string, ld: date) throws
proc set(tbl: string, ti: time) throws
proc set(tbl: string, dt: dateTime) throws
proc set(tbl: string, A: [?D] shared Toml?) throws  where D.isAssociative()
proc set(tbl: string, arr: [?dom] shared Toml?) throws  where !dom.isAssociative()
override proc serialize(writer, ref serializer) throws

Write a Table to channel f in TOML format.

Throws:

TomlError – If an error occurred serializing the table, such as due to missing values or unsupported types.

proc writeTOML(f)

Write a Table to channel f in TOML format

proc writeJSON(f)

Write a Table to channel f in JSON format

proc toString() : string

For the user to write values of a node as follows: Toml[key].toString()

proc tomlType : string throws

Return Toml type as a string.

Valid types include:

  • empty

  • string

  • integer

  • float

  • boolean

  • datetime

  • array

  • toml (inline table)

Throws:

TomlError – If this is not a known TOML type.