DSMBuilder

class dsviper.DSMBuilder

Bases: object

Assembles a DSM model from several sources.

DSM is the human form of what Definitions, Type and Attachment build through the API: a namespace holds concepts, structures, enumerations and clubs, plus the attachments that file a document under a key, and a function pool declares the functions that act on them.

Every type and attachment declared there can be built through the API and read back with DSMDefinitions.from_definitions(); a function pool is read back from its runtime FunctionPool with from_function_pool(). The reverse is DSMDefinitions.to_dsm(), which renders definitions you already hold back as DSM source.

append(source: str, content: str) → None

Append one part of the model, under the name it is known by.

source is that name - a file name, or anything the parse report can point back to. content is the DSM text.

A namespace carries a name and a uuid in braces, and holds the declarations:

namespace App {6f9619ff-8b86-d011-b42d-00cf4fc964ff} {

concept User; struct Profile { string name; optional<uint32> age; }; attachment<User, Profile> profile;

};

That is the shape, not the whole language: a concept specialises another with ‘is a’, and clubs, memberships, enumerations, field defaults and doc comments sit in the namespace beside these.

A function pool does not: it is declared beside the namespace, at the level of the part, and carries a uuid of its own.

function_pool Tools {dc9740c9-9d1d-4c1e-9caa-4c8843b91e82} {

int64 add(int64 a, int64 b);

};

static assemble(path: str) → DSMBuilder

Return a DSMBuilder with the concatenated content of the DSM files found at the path where the path is a file or a folder.

content() → str

Return every appended part concatenated, which is what parse() reads.

line_offset() → int

Return the line the next appended part will start at, counting from 1.

parse(*, source_map: DSMSourceMap | None = None) → tuple[DSMParseReport, DSMDefinitions | None, DefinitionsConst | None]

Parse the assembled content and return (DSMParseReport, DSMDefinitions, DefinitionsConst).

The last two are None when parsing failed; the report says why. Pass a DSMSourceMap as source_map to have the source spans filled in as it parses.

What the text declared is reached by name through a DefinitionsInspector over the DefinitionsConst: check_attachment(‘App::User.profile’) answers the Attachment to write with, check_structure(TypeName(ns, ‘Profile’)) the type.

part(line: int) → DSMBuilderPart | None

Return the part associated with the line number, or None if no part covers it.

parts() → list[DSMBuilderPart]

Return the list of parts.