DSM Introspection

DSM classes provide parsing and introspection of Digital Substrate Model files.

When to use: Use DSMBuilder to parse .dsm files and introspect the resulting definitions (structures, enumerations, attachments, functions).

Quick Start

from dsviper import DSMBuilder

# Parse DSM file
builder = DSMBuilder.assemble("model.dsm")
report, dsm_defs, defs = builder.parse()

# Check for parse errors
if report.has_error():
    for err in report.errors():
        print(f"Line {err.line()}: {err.message()}")
    raise RuntimeError("DSM parse failed")

# Introspect structures
for struct in dsm_defs.structures():
    print(f"Struct: {struct.type_name()}")
    for field in struct.fields():
        print(f"  {field.name()}: {field.type_reference()}")

# Introspect attachments
for att in dsm_defs.attachments():
    print(f"Attachment: {att.type_name()}")
    print(f"  Key: {att.key_type()}, Doc: {att.document_type()}")

# Inject constants for runtime use
defs.inject()  # Creates MYAPP_A_*, MYAPP_S_*, etc.

Parsing

dsviper.DSMBuilder

A class used to assemble a collection of DSM Definitions from various sources.

dsviper.DSMBuilderPart

A class used to represent a part of the assembled definitions.

dsviper.DSMDefinitions

A class used to represent DSM definitions.

dsviper.DSMDefinitionsInspector

DSMDefinitionsInspector(definitions).

dsviper.DSMParseReport

A class used to collect the error occurred while parsing the assembled definitions.

dsviper.DSMParseError

A class used to represent a parse error.

Model Elements

dsviper.DSMConcept

A class used to represent the definition of a concept.

dsviper.DSMClub

A class used to represent the definition of a club.

dsviper.DSMStructure

A class used to represent the definition of a struct.

dsviper.DSMStructureField

A class used to represent the definition of a field for a struct.

dsviper.DSMEnumeration

A class used to represent the definition of an enum.

dsviper.DSMEnumerationCase

A class used to represent the definition of a case for an enum.

dsviper.DSMAttachment

A class used to represent the definition of an attachment.

DSM Types

dsviper.DSMTypeKey

A class used to represent the type key<element_type>.

dsviper.DSMTypeVector

A class used to represent the type vector<element_type>.

dsviper.DSMTypeSet

A class used to represent the type set<element_type>.

dsviper.DSMTypeMap

A class used to represent the type map<key_type, element_type>.

dsviper.DSMTypeXArray

A class used to represent the type xarray<element_type>.

dsviper.DSMTypeOptional

A class used to represent the type optional<element_type>.

dsviper.DSMTypeTuple

A class used to represent the type tuple<T0, ...>.

dsviper.DSMTypeVec

A class used to represent the type vec<element_type, size>.

dsviper.DSMTypeMat

A class used to represent the type vec<element_type, columns, rows>.

dsviper.DSMTypeVariant

A class used to represent the type variant<T0, ...>.

dsviper.DSMTypeReference

A class used to represent a reference to a type.

Functions

dsviper.DSMFunction

A class used to represent the definition of a function.

dsviper.DSMFunctionPool

A class used to represent the definition of a function pool.

dsviper.DSMFunctionPrototype

A class used to represent the definition of a function prototype.

dsviper.DSMAttachmentFunction

A class used to represent the definition of an attachment function.

dsviper.DSMAttachmentFunctionPool

A class used to represent the definition of an attachment function pool.

Literals

dsviper.DSMLiteralValue

A class used to represent the definition of a literal value.

dsviper.DSMLiteralList

A class used to represent the definition of a literal list.