Class TomlPositions

java.lang.Object
be.imgn.toml.TomlPositions

public final class TomlPositions extends Object
Where the keys and values of a parsed document are written, to report a problem with one at its line and column.
var document = Toml.parse(file);
var save = document.root().getTable("commands.save");
if (!save.entries().containsKey("command")) {
    var position = document.positions().key(document.root().getTable("commands"), "save");
    report(position.line(), position.column(), "[commands.save] names no command");
}

A position is looked up by the table or array that holds the key or the element, which must be the very instance the parse returned: positions compare tables and arrays by identity, as equal tables can be written in several places. A copy of a table, such as one built from it with TomlTable.toBuilder(), has no positions.

The key is a key of that table, never a dotted path: the position of port in [server] is key(root.getTable("server"), "port").

Since:
0.1.0
  • Method Details

    • key

      public TomlPosition key(TomlTable table, String key)
      Returns where a key of a table is written.

      That is the key itself, or its own part of a dotted key: the position of save in [commands.save] is that of save. A table that is defined in several places, as a table implicitly defined by [a.b] and then by [a], is at its header. An array of tables is at its first header.

      Parameters:
      table - a table of the document
      key - a key of table
      Returns:
      the position of key
      Throws:
      IllegalArgumentException - if table is not a table of the document, or has no key key
      NullPointerException - if an argument is null
    • value

      public TomlPosition value(TomlTable table, String key)
      Returns where the value of a key of a table starts.

      That is the first character of the value, which is the opening bracket or brace of an array or an inline table. For a table defined by a header, it is the header's opening bracket, and for an array of tables, its first header's. A table that only exists as the parent of others, as a for [a.b] or a.b = 1, is at its key.

      Parameters:
      table - a table of the document
      key - a key of table
      Returns:
      the position of the value of key
      Throws:
      IllegalArgumentException - if table is not a table of the document, or has no key key
      NullPointerException - if an argument is null
    • element

      public TomlPosition element(TomlArray array, int index)
      Returns where an element of an array starts.

      That is the first character of the element, as for value(TomlTable, String). The element of an array of tables is at the opening bracket of its header.

      Parameters:
      array - an array of the document
      index - the index of an element of array
      Returns:
      the position of the element
      Throws:
      IllegalArgumentException - if array is not an array of the document
      IndexOutOfBoundsException - if index is not an index of array
      NullPointerException - if array is null