Sources and registries

Collections of sources, units, schemas, functions, and node hierarchies.

enum class snt::dip::FunctionKind

Values:

enumerator Value
enumerator Nodes
OverrideItemTarget snt::dip::classify_override_item(const HierarchyList &hierarchy, const std::string &requested)
struct Branch

Branch containing the cases selected during DIPL evaluation.

Public Members

std::vector<size_t> cases
std::vector<CaseType> types
std::map<std::string, size_t> nodes
class BranchingList

Collection of DIPL branches and their selected cases.

Public Functions

inline BranchingList()
int register_case()
bool false_case()
void solve_case(const BaseNode::PointerType &node)
void prepare_node(const BaseNode::PointerType &node)
std::string clean_name(const std::string &node) const
bool is_internal_path(const std::string &path) const

Whether a path contains a parser-owned case component.

std::vector<size_t> active_case_ids() const

Current decision IDs, from outermost to innermost branch.

struct Case

One conditional case in a DIPL branching structure.

Public Members

std::string path
std::string code
std::string expr
bool value
size_t branch_id
size_t branch_part
size_t case_id
CaseType case_type
struct Collection

Information about a collection, keyed or indexed

Public Members

std::string path

Fully qualified path of a collection.

std::vector<std::string> items

List of collection items.

Path::Kind kind

Collection path kind.

std::vector<std::string> schemas

List of item schemas.

ValueMetadata metadata

Metadata attached to this explicit group or collection node.

std::vector<std::string> children

Direct named children in declaration order for groups and items.

std::vector<MetadataConstraint> metadata_constraints
struct EnvFunction

Traceable registered DIPL function.

Public Members

std::string id

Internal trace identifier, e.g. DIP0_FUNCTION0.

std::string name

Public function name used by DIPL.

FunctionKind kind
struct EnvSchema

Reusable schema definition registered in a parsed DIPL environment.

Public Members

std::string name
BaseNode::ListType nodes
std::string id
ValueMetadata metadata

Metadata on the definition, not inherited by instances.

std::vector<MetadataConstraint> instance_metadata_constraints
std::string source_name

Source containing the declaration or schema body.

size_t source_line

Declaration line, or first body line for host schemas.

std::string registration_source_name

Source that registered a host schema, when available.

size_t registration_line

One-based host declaration line.

struct EnvSource

Named DIPL source text together with its parsed nodes.

Public Members

std::string name

Source lookup key.

std::string path

Original source path.

std::string code

Exact source text.

Source parent

Source that introduced this entry.

NodeList<ValueNode> nodes

Parsed source nodes.

bool named_source

Whether source?path references can use this entry.

bool raw_text

Whether content is kept verbatim instead of parsed as DIPL.

bool table_text

Whether raw content was parsed as a table.

std::string table_path

Resolved table populated by this raw source, if any.

HierarchyList hierarchy

Hierarchy local to this source.

SchemaList schemas

Schemas available to imported collections.

ExplicitDeclarations declarations

Explicit source-local paths.

bool embedded

Whether code came from memory rather than path.

ValueMetadata metadata

Metadata declared at the source root.

struct EnvUnit

Custom unit data

Public Members

std::string name

unit key

std::string definition

unit definition

size_t stack

number of the current unit system stack

std::string id

Internal trace identifier, e.g. DIP0_UNIT0.

size_t registration_order

Environment-local registration order.

std::string source_name

Parsed source containing the declaration, when available.

size_t source_line

One-based declaration line in that source.

class FunctionList

Registry of functions callable from DIPL expressions.

Public Types

using DataFunctionType = std::function<ValueNodeData(const Environment&)>
using NodesFunctionType = std::function<ValueNode::ListType(const Environment&)>

Public Functions

void append_value(const std::string &name, DataFunctionType func, const std::string &parent_id = {})

Register a value function under a public name and trace parent identifier.

void append_nodes(const std::string &name, NodesFunctionType func, const std::string &parent_id = {})

Register a node-producing function under a public name and trace parent identifier.

DataFunctionType get_value(const std::string &name) const

Return the registered value-producing function.

Parameters:

name – Function name to look up.

NodesFunctionType get_nodes(const std::string &name) const
const EnvFunction &get_value_info(const std::string &name) const

Return trace information for a registered value function.

const EnvFunction &get_nodes_info(const std::string &name) const

Return trace information for a registered node-producing function.

std::vector<EnvFunction> entries() const

Return trace information for all registered functions, ordered by name and kind.

class HierarchyList

The main class that manages node hierarchy

Public Functions

void record(const BaseNode::PointerType &node, const std::vector<NodeDtype> &excluded, const std::function<std::string(const std::string&)> &collection_path = {})

Register node into the node hierarchy

Parameters:
  • node – Node that should be registed

  • excluded – List of node types that will be ignored in a node hierarchy

void record_parent(const BaseNode::PointerType &node)

Update indentation context without creating nodes or collection items.

const Path get_current_path(size_t indent = 0, const std::string &path = "", bool show_item = true) const

Get path of the current hierarchy level

If indent and path is not provided, method returns the most recent path composed from parents in the stack. When provided, the method returns path relative to the given indent. E.g. if current path is ‘foo.bar.baz’ and group ‘bar’ has indent 2, than for input indent 2 and path crackle, the following path will be constructed: foo.crackle.

The paramer show_item strips the item from the end of the collection path: e.g. instead of foo[bar] only foo is returned

Parameters:
  • indent – Indent of a new node

  • path – Path name of a new node

  • show_item – Show collection item at the end of the path

Returns:

Path of the current hierarchy level

std::string resolve_list_selectors(std::string path) const

Replace implicit list selectors with the current item indices.

const std::unordered_map<std::string, Collection> &get_collections() const

Gets a reference on a ll collections

Returns:

Map of all collections

const Collection &get_collection(const std::string &path) const

Get reference to a specific collection

Parameters:

path – Collection fully qualified path

Returns:

Referenc on a collection

void set_collection(const std::string &path, Path::Kind kind, std::vector<std::string> schemas)

Set a new collection

Parameters:
  • path – Collection fully qualified path

  • kind – Collection kind (map/list)

  • schemas – List of schemas applied to collection items

void set_collection(const std::string &path, Path::Kind kind, std::vector<std::string> schemas, std::vector<std::string> items)

Restore a collection and its item order from persisted environment data.

void import_subtree(const HierarchyList &source, const std::string &source_root, const std::string &target_root)

Copy evaluated collection structure under a new import path.

std::vector<std::string> subtree_schemas(const std::string &source_root) const

Names of schemas applied within a selected collection subtree.

void erase_collection(const std::string &path)

Remove a collection entry after parse-time path bookkeeping is complete.

void set_schemas(const std::string &path, std::vector<std::string> schemas)

Record schemas applied to an existing group or collection item.

void record_ordered_path(const std::string &path)

Record a resolved node path in its parent’s declaration order.

inline const std::vector<std::string> &root_children_order() const

Direct top-level DIPL child names in declaration order.

void merge_metadata(const std::string &path, const ValueMetadata &metadata)

Merge explicit metadata fields attached to a hierarchy node.

const bool has_collection(const std::string &path) const

Test if collection whith the given path exists

Parameters:

path – Collection path that should be found

Returns:

Returns true if collection exists, otherwise returns false

const size_t num_collections() const

Get number of collections

Returns:

Number of collections

template<typename T>
class NodeList

Ordered, named collection of DIPL nodes.

Public Functions

NodeList() = default
inline NodeList(const typename T::ListType &nl)
inline size_t size() const
inline void push_front(const typename T::PointerType &node)
inline void push_back(const typename T::PointerType &node)
inline T::PointerType pop_front()
inline void erase(size_t index)
inline T::PointerType pop_back()
inline T::PointerType at(const size_t index)
inline T::PointerType at(const size_t index) const
inline const T::ListType &get_nodes() const
struct OverrideItemTarget

Static classification of a terminal collection-item override path. It does not evaluate the item or its child values.

Public Types

enum class Status

Values:

enumerator Existing
enumerator Creatable
enumerator UnknownCollection
enumerator InvalidSelector
enumerator SchemaRequired
enumerator UnresolvedParent

Public Members

Status status
std::string resolved_path
std::vector<std::string> schemas
class OverrideList

Collected, exact-path value modifications applied before node evaluation.

Public Functions

void append(const BaseNode::PointerType &node)

Register one modification; a repeated target is an error.

void append(const BaseNode::ListType &nodes, size_t indent)

Atomically collect a body, expanding indentation into fully qualified target paths.

BaseNode::PointerType find(const std::string &path) const

Find a modification by fully qualified target path, or return nullptr.

void consume(const std::string &path)

Mark a target consumed after successful application.

std::vector<std::string> unresolved() const

Return all target paths not matched by a normal declaration.

size_t item_group_count() const

Number of terminal item groups, in registration order.

BaseNode::PointerType materialize_item_group(size_t index, const HierarchyList &hierarchy)

Return a new group for an absent item, or nullptr for an existing item.

struct Parent

Holds information about a paraent node in the hierarchy

Public Members

size_t indent

Indent of a parent node.

std::string name

Fully qualified node path.

std::vector<Path::CollectionAccess> collections

List of collections in the node path.

class SchemaList

Public Functions

SchemaList()
void append(const std::string &name, BaseNode::ListType &nodes, const std::string &parent_id = {}, const ValueMetadata &metadata = {}, size_t source_line = 0, const std::vector<MetadataConstraint> &instance_constraints = {})

Append a schema definition to the registry.

Parameters:
  • name – Name used to identify the item.

  • nodes – Nodes defining the schema.

  • parent_id – Internal identifier of the registering source.

  • metadata – Metadata attached to the schema definition.

void append(const std::string &name, EnvSchema src, const std::string &parent_id = {})

Append a schema record, assigning an identifier when it has none.

void import_referenced_from(const SchemaList &source, const std::vector<std::string> &names)

Import selected definitions and their dependencies, rejecting conflicting names.

EnvSchema &at(const std::string &name)
const EnvSchema &at(const std::string &name) const
const std::map<std::string, EnvSchema> &entries() const

Return all registered schema definitions and metadata keyed by name.

class SourceList

Collection of named DIPL sources.

Public Functions

SourceList()
void append(const std::string &name, const std::filesystem::path &path, const std::string &code, const Source &parent)

Append an item to the collection.

Parameters:
  • name – Name used to identify the item.

  • path – Path identifying the requested node or source.

  • code – Source code associated with the source entry.

  • parent – Parent source metadata used to preserve include provenance.

void append(const std::string &name, const EnvSource &src)
EnvSource &at(const std::string &name)
const EnvSource &at(const std::string &name) const
const std::map<std::string, EnvSource> &entries() const

Return all registered sources keyed by their DIPL source name.

inline const std::vector<std::string> &registration_order() const

Source names in the order they were registered during parsing.

class UnitList

List of custom units

Public Functions

UnitList()

Unit list constructor

void append(const std::string &name, const std::string &definition, const std::string &parent_id = {})

Append new custom unit from a name and a definition expression

Parameters:
  • name – Name of a custom unit

  • definition – Expression that defines a new unit

  • parent_id – Internal identifier of the registering source.

void append(const std::string &name, EnvUnit data, const std::string &parent_id = {})

Append new custom unit from a name and a custom unit data

Parameters:
  • name – Name of a custom unit

  • data – Custom unit data object

  • parent_id – Internal identifier of the registering source.

EnvUnit &at(const std::string &name)

Select custom unit data

Parameters:

name – Name of a custom unit

Returns:

Custom unit data

const EnvUnit &at(const std::string &name) const

Select custom unit data for read-only

Parameters:

name – Name of a custom unit

Returns:

Custom unit data

const std::map<std::string, EnvUnit> &entries() const

Return all registered custom units keyed by unit name.