|
TraceMaker
C++ API of the engine
|
#include <sexpr/sexpr.hpp>
Public Member Functions | |
| NodeId | root () const |
| const Node & | node (NodeId id) const |
| std::size_t | node_count () const |
| const std::string & | text () const |
| std::span< const NodeId > | children (NodeId list) const |
| -— navigation -— | |
| NodeId | child (NodeId list, std::size_t i) const |
| std::string_view | head (NodeId list) const |
| First token of a list, e.g. "segment" for (segment ...). Empty for atoms or empty lists. | |
| bool | is_list (NodeId id) const |
| NodeId | find (NodeId list, std::string_view name) const |
| First child list whose head is name, or kNoNode. | |
| std::vector< NodeId > | find_all (NodeId list, std::string_view name) const |
| All child lists whose head is name. | |
| std::string_view | raw (NodeId id) const |
| -— atoms -— Raw source text of a node (for strings, including quotes). | |
| std::string | str (NodeId atom) const |
| Atom value: symbols as-is, strings unescaped. | |
| std::string | str_at (NodeId list, std::size_t i) const |
| Value of the i-th child atom of list (i counts the head as 0). | |
| std::optional< double > | number_at (NodeId list, std::size_t i) const |
| std::optional< std::int64_t > | nm_at (NodeId list, std::size_t i) const |
| Parses a decimal millimetre value to integer nanometres exactly (no binary floating point). | |
| int | line_of (std::size_t offset) const |
| 1-based line number of a byte offset (for error messages). | |
| void | replace (NodeId id, std::string new_text) |
| -— edits (applied by write()) -— Replaces the node's text. | |
| void | remove (NodeId id) |
| Removes the node together with its leading whitespace on the same line and the line break, when the node occupies whole lines; otherwise removes the node and one preceding space. | |
| void | append_child (NodeId list, std::string_view text) |
| Inserts text as new children at the end of list, each on its own line, indented one level deeper than the list's own line. | |
| bool | modified () const |
| std::string | write () const |
| Text after applying all edits. | |
| void | save (const std::string &path) const |
| std::string_view | indent_of (std::size_t offset) const |
| The indentation (tabs/spaces) at the start of the line containing offset. | |
Static Public Member Functions | |
| static Document | parse (std::string text) |
| Parses text. Throws ParseError on malformed input. The document owns a copy of the text. | |
| static Document | load (const std::string &path) |
| void tmk::sexpr::Document::append_child | ( | NodeId | list, |
| std::string_view | text ) |
First child list whose head is name, or kNoNode.
All child lists whose head is name.
| std::string_view tmk::sexpr::Document::head | ( | NodeId | list | ) | const |
First token of a list, e.g. "segment" for (segment ...). Empty for atoms or empty lists.
| std::string_view tmk::sexpr::Document::indent_of | ( | std::size_t | offset | ) | const |
The indentation (tabs/spaces) at the start of the line containing offset.
|
inline |
| int tmk::sexpr::Document::line_of | ( | std::size_t | offset | ) | const |
1-based line number of a byte offset (for error messages).
|
static |
| std::optional< std::int64_t > tmk::sexpr::Document::nm_at | ( | NodeId | list, |
| std::size_t | i ) const |
Parses a decimal millimetre value to integer nanometres exactly (no binary floating point).
|
inline |
| std::optional< double > tmk::sexpr::Document::number_at | ( | NodeId | list, |
| std::size_t | i ) const |
|
static |
Parses text. Throws ParseError on malformed input. The document owns a copy of the text.
|
inline |
| void tmk::sexpr::Document::remove | ( | NodeId | id | ) |
Removes the node together with its leading whitespace on the same line and the line break, when the node occupies whole lines; otherwise removes the node and one preceding space.
| void tmk::sexpr::Document::replace | ( | NodeId | id, |
| std::string | new_text ) |
-— edits (applied by write()) -— Replaces the node's text.
| void tmk::sexpr::Document::save | ( | const std::string & | path | ) | const |
| std::string tmk::sexpr::Document::str | ( | NodeId | atom | ) | const |
Atom value: symbols as-is, strings unescaped.
| std::string tmk::sexpr::Document::str_at | ( | NodeId | list, |
| std::size_t | i ) const |
Value of the i-th child atom of list (i counts the head as 0).
|
inline |
| std::string tmk::sexpr::Document::write | ( | ) | const |
Text after applying all edits.