sbdl
Append or merge data into an existing list or dict config value, skipping locked keys.
Read a mix of SBDL sources and SQL databases, auto-detecting database inputs.
Read CSV files from input_list and return (parser_elements, error_count).
Read all files/directories in input_list and return (parser_elements, error_count).
Read JSON files from input_list and return (parser_elements, error_count).
Read SBDL-schema SQL databases from input_list and return (parser_elements, error_count).
Read YAML files from input_list and return (parser_elements, error_count).
Return the icon and a trailing space when it may decorate text meant for a person: pretty
printing allowed and, when file is given, that stream a terminal (or assumed one) able to
encode it. Otherwise an empty string, so undecorated output stays byte-for-byte stable.
Return the live configuration dict (read/iterate/in-place mutation).
Return the default-configuration snapshot taken by init().
Print formatted output to stdout (or stderr for errors/warnings) with optional ANSI colour codes.
Retrieve a configuration value by key, with optional environment variable override and numeric coercion.
Read the file at filepath line-by-line, apply directives, and append SBDL_Parser.Parser_Element objects to elements_list.
Return the application help text string.
Return the application icon (an emoji standing in for the logo where only text fits).
Dynamically load a Python file and merge its DIRECTIVES dict into the global parser directives.
Dynamically load a Python file defining custom output modes and register them.
Snapshot the current configuration as the default state for later reset.
Return the name of the license the compiler is provided under.
Return the license text itself.
Return the URL of the published license text.
Load a JSON configuration file and merge its values into the global config.
Lives in core (a config operation, also invoked by the model's config directives) but reaches the IO layer's file opener lazily to keep core a leaf.
Lock a configuration key so it cannot be modified by subsequent set_config_value calls.
Return the application logo string, or empty string if pretty-print is disabled.
Entry point for a single compilation run: read inputs, build AST, apply filters, verify, and write output.
Return the application name.
Utilities for generating FMEA table data from an SBDL AST.
Traverse the fully-connected CME graph and return a list of FMEA row dicts.
Wrap an FMEA table in an OpenFMEA metadata envelope dict.
Open an OpenFMEA JSON file and return its parsed dict content.
Serialise open_sbdl_struct as JSON to open_sbdl_file, with optional pretty-printing.
Parse and verify an OpenFMEA JSON file, raising if the format or type is incorrect.
Generate an OpenFMEA JSON file from the AST and write it to output_file.
Generate an OpenFMEA Portfolio JSON file, organising FMEA rows by aspect hierarchy.
Convert an OpenFMEA table (list of row dicts) back into a list of SBDL_Element_Synthetic objects.
Convert general (non-FMEA) OpenFMEA entries into SBDL_Element_Synthetic objects linked to fmea_elements.
Progress bar for one compilation stage, drawn on stderr. Inert unless sbdl_progress (--progress) is set and stderr is a terminal. 'active' and 'depth' are process-wide.
Iterate items, drawing a stderr progress bar for the stage when enabled. detail, if given, maps an item to the text shown after the count while it is being processed; the bar repaints as each item starts, so a slow item is named while it runs.
Print a human-readable summary of every element in the AST to stdout.
Register a zero-arg callable to be run by reset() (e.g. the model clearing its custom-type registry). Lets reset() live in core -- with init/config -- without core depending on other modules: each module registers its own reset behaviour.
Restore configuration to the initial default snapshot and run all registered reset hooks, clearing every module's global mutable state between compilations.
SBDL element representing an architectural aspect (system decomposition unit).
Return the type name string for this element class; None for the abstract base.
Return True if this aspect's stereotype is compatible with the target link's target stereotype.
Abstract Syntax Tree for an SBDL model: parses statements, builds elements, runs verification hooks.
Replace the internal parsed object list (used for testing or pre-built ASTs).
Report any parsing errors in the AST and return the error count.
Alias for elements(); build and return the SBDL element dict from the AST.
Build SBDL elements from parsed statements, apply directives and hooks, return (elements, error_count).
Build the incoming-relations table of an element set: for every element, the relations that other elements declared towards it.
Return all parents (or children) for an element, including those declared on the other side of the link.
Return all parents for an element including those declared by child links in other elements.
Return all children for an element including those declared by parent links in other elements.
Return all relation links for an element including those declared on the other side.
Return the combined list of all parents, children, relation and 'related' links for an element.
Return the set of element identifiers that are not children of any other element.
Verify all elements and their links in sbdl_elements; report errors and return (result, error_count).
Build a cross-reference dict (keyed by identifier) of all element data for macro expansion.
Build a fully-connected cause-mode-effect graph, inserting placeholder nodes where links are absent.
Return a filtered copy of element_set containing only elements for which filter_pred_f returns True.
Register a filter predicate f(element, element_set, incoming, relation_cache) -> bool to be applied when retrieving elements; incoming is build_incoming_relations() of the set and relation_cache a per-pass dict, both for connectivity walks and ignorable otherwise.
Return True if a connectivity walk may end at this element but must not continue through it.
Recursively traverse element links to determine whether any reachable element matches filter_id, with memoisation.
Add a filter that retains elements reachable via links ('related' included) from elements matching filter_id, up to depth_bound.
Add a filter that retains elements connected (parents, links, children) to elements matching filter_id, up to depth_bound.
Add a filter that retains elements whose ancestors match filter_id, up to depth_bound.
Add a filter that retains elements whose descendants match filter_id, up to depth_bound.
Add a filter that retains only elements whose type matches the regex filter_id.
Element representation of a 'customtype' declaration that registers a new user-defined type.
Parsed 'customtype' declaration statement that introduces a user-defined element type.
Parsed SBDL element declaration holding an identifier, declared type, and key-value attribute data.
Return a synthetic identifier composed of statement type and source reference.
SBDL element representing a prescriptive design definition.
Element representation of a 'depends' statement that imports external files.
Parsed 'depends' statement that imports external files into the current scope.
Base class for all SBDL model elements, providing type, links, properties, and verification infrastructure.
Return the type name string for this element class; None for the abstract base.
Return True if this element is an instance of, or has a type matching, the given target type/class/name.
Return the element identifier, optionally including the stereotype suffix.
Return the description property of this element with escape characters resolved.
Expand all macro directives within this element's properties and links using the provided macro dict.
Return the element's full data as a plain dict, optionally including extra links.
Return an SBDL_Declaration_Statement reconstructed from this element's current state.
Return the 'file:line' reference of the source text which declared this element.
Unlike reference(), this is never replaced by a 'reference' property, so it always points at real source. Use it for compiler diagnostics; reference() remains correct for output formats, where a user-supplied reference is the intended value.
Return the source reference string for this element (file:line or overridden reference property).
Return the list of type names for this element's class hierarchy (from most to least derived).
Return a copy of this element's relation (link) list, excluding 'related' links.
'related' links share the common link list but are excluded here so that every existing consumer of links() keeps its exact meaning -- notably the link verification in check_semantics, whose type checks a 'related' link (whose type is 'related', never its target's type) could not satisfy. Use related() for those, or _iter_links() for the raw list traversal code needs.
Return the value of the named property (value_only specifies that stereotype should be removed from result).
Return the SBDL_Element subclass corresponding to the given type name string.
Instantiate and return the appropriate SBDL_Element subclass for the given declaration statement.
Convert a parsed statement object into the corresponding SBDL_Element instance.
Return True if a link between this element's type and the given link's type is semantically valid.
Return True if the parent link type is compatible with this element's type hierarchy.
Return True if the child link type is compatible with this element's type hierarchy.
Extended relation validation hook; returns (True, '') by default.
Verify all links on this element, checking stereotypes and hash integrity; return (is_valid, error).
Return a comma-separated string of link identifiers, optionally filtered by element type.
Represents a directed link (relation) from one SBDL element to another, carrying type and optional stereotype/hash.
Return the target element identifier, optionally including stereotype and hash suffixes.
Base class for SBDL elements that carry a numerical rating (detectability, severity, or occurrence).
Return the element's rating value, returning the post-action value when post=True if available.
Mapping of element type names to their respective rating attribute names.
Programmatically constructed SBDL element not backed by a parsed declaration statement.
Create an SBDL_Element_Synthetic that is a copy of the given SBDL element.
Construct and return an SBDL_Declaration_Statement representing this synthetic element.
Set the (pre- or post-action) rating value for this synthetic element.
Convert this synthetic element back to a native SBDL_Element via a declaration round-trip.
SBDL element representing a dynamic system event, optionally with conditions and alternative branches.
Return the type name string for this element class; None for the abstract base.
SBDL element representing an improvement action to prevent a failure cause or mode.
SBDL element representing an improvement action to increase detection of a failure mode.
SBDL element representing a FMEA failure cause with optional occurrence rating.
Return the type name string for this element class; None for the abstract base.
SBDL element representing an existing control that prevents a failure cause or mode.
SBDL element representing an existing detection (test) that measures failure mode occurrence.
SBDL element representing a FMEA failure effect with optional severity rating.
Return the type name string for this element class; None for the abstract base.
SBDL element representing a FMEA failure mode with optional detectability rating.
Return the type name string for this element class; None for the abstract base.
Return True if the parent link type is compatible with this element's type hierarchy.
Return True if the child link type is compatible with this element's type hierarchy.
SBDL element representing a system function with optional parent/child hierarchy.
SBDL element representing a structural grouping of other elements with no semantic implications.
SBDL element representing an external interface exposed by an aspect.
Parsed operator statement (e.g. link or source-link operator between elements).
Abstract base for all parsed SBDL objects; raises on any unimplemented interface method.
Container for SBDL language parser constants, token rules, directive handling, and parsing logic.
Switch the parser lexical spec to use the formal (Unicode symbol) grammar variant.
Represents a single parsed text element with its source location and line index information.
Return a formatted string showing content with line numbers derived from the index map.
Return the full list of (content_position, line_number) index pairs for this element.
Return all index pairs whose content position is at or after pos (and before until, if given).
The upper bound is applied here so the caller does not receive, and then discard, the whole tail of the index list per statement.
SBDL element representing a technical realisation of a design definition.
SBDL element representing a system requirement or acceptance criterion.
Element representation of a 'scope' statement that applies namespace prefixes.
Parsed 'scope' statement that applies a namespace prefix to identifiers in the current block.
Container for SBDL semantic rules: allowed type links, type properties, type/category/property descriptions, and custom type registration.
Return a list of valid relation target type names for the given element type name.
Build and return a comprehensive dict describing all language types, properties, directives, and CLI help.
Return (and memoize) a consistent hex color string for the given element type name.
Calculate a Behavioural Specification Complexity Index (BSCI) score for the given statement text.
Derive a compact SBDL identifier from a natural-language string by applying stop-word removal, abbreviations, and vowel elision.
Derive a compact identifier using the v2 engineering standard stop-word/abbreviation set.
Derive a compact identifier using the v1 engineering standard stop-word/abbreviation set.
Derive a compact identifier using the default engineering standard rules.
Return the last shorten_length characters of input_string, aligned to a word boundary.
Generate a short, base-62-encoded unique identifier from a SHA-256 hash of the input string.
SBDL element representing a system state with optional parent/child hierarchy.
Concrete parsed statement holding its parser element, type, attribute data, and error state.
Return the attribute data dict, injecting the syntactic parent as a parent attribute if present.
Return the character position within the content where the error occurred.
Merge parent_data into this statement's data dict.
For keys that exist only in parent_data, they're added as-is.
For keys that exist in both dictionaries, behavior depends on append:
- If append=True, the parent's value is appended to the existing value with a ", " separator (existing first, then parent).
- If append=False (default), the existing value is preserved and the parent's value is discarded.
Prepend scope prefixes to matching attribute values and return the resulting scope map.
SBDL element representing a test instance for a particular design element.
SBDL element representing a dynamic trace instance embedded in a log or execution record.
SBDL element representing a state transition; must reference exactly one ordered pair of states.
Return the type name string for this element class; None for the abstract base.
SBDL element representing a system use case with an optional actor property.
Element representation of a 'using' statement that imports shared attributes.
Parsed 'using' statement that imports attributes from named element definitions into the current scope.
Replace the entire configuration dict.
Set a configuration value by key, warning if the key is new and skipping if locked.
Set the application help text string (loaded lazily from the manual).
Set the application logo string (the large ANSI banner is assigned at startup).
Classify an input path for the SQL backend, by content not extension.
Returns 'remote' for a recognised mysql/mariadb DSN, 'sqlite' for a local file that begins with the 16-byte SQLite header, or None for an ordinary SBDL source (file, directory, or stdin). Used to auto-detect database inputs so a DB can be fed to any output mode directly, without an explicit from:sql step.
Render infile as a docxtpl Word template with template_dict context and save to outfile.
Release a configuration key lock, allowing subsequent set_config_value calls to take effect.
Return the project URL.
Merge new_config_data into the global config, skipping locked and explicitly excluded keys.
Return the current compiler version string.
Return the development version marker string.
Return the DSL language specification version string.
Return the REST API version string.
Write all AST elements as SBDL statements to output_file, optionally sorted and pretty-printed.
Generate a PlantUML component/decomposition diagram from the AST and write it to output_file.
Generate a CSV FMEA table from the AST and write it to output_file.
Generate a detailed PlantUML element diagram showing all element properties and relations.
Generate a PlantUML sequence diagram of function/event flows and write it to output_file.
Write a flat CSV matrix of all element attributes (from the full AST dict) to output_file.
Write the full AST as an indented JSON dict to output_file.
Generate a networkx/matplotlib network graph of all elements and write it to output_file.
Generate a PlantUML activity/process diagram from the AST and write it to output_file.
Generate a PlantUML requirements diagram from the AST and write it to output_file.
Send AST elements to a remote REST endpoint for processing and write the response to output_file.
Generate an interactive Sigma.js HTML network graph from the AST and write it to output_file.
Materialise the SBDL element model into a normalised SQL database.
The model is written into three related tables so that relations -- including structural parent/child links -- become first-class, joinable rows pointing at other elements:
- elements(identifier PK, type, types, stereotype, description, reference, hash) -- one row per SBDL element. 'description' and 'reference' are promoted to columns as the two most commonly queried properties.
- properties(element_id FK, name, value) -- every other property (tags, FMEA ratings, conditions, custom: attributes ...) as entity-attribute-value rows, so arbitrary/custom properties need no schema change.
- relations(source_id FK, relation, target_id, stereotype, hash, derived) -- every typed relation as a directed edge. 'relation' is the SBDL relation name ('aspect', 'requirement', 'fmea:mode', 'parent', 'child', ...). Both reciprocal halves are kept (distinct named relations) with 'derived' flagging the bijective reverse half (1) versus the forward-declared link (0); exact duplicate edges are de-duplicated.
- customtypes(name, declaration, ordinal) -- each custom type's verbatim canonical declaration, in source order, so 'from:sql' can re-emit them ahead of the elements that use them and round-trip custom typing losslessly.
A small sbdl_meta(key,value) table records the schema version, generator version and a timestamp to support future synchronisation/diffing and the 'from:sql' reconstruction reader.
The backend is selected from the output locator (-o): a plain path writes a local SQLite file; a 'mysql://'/'mariadb://' DSN selects a remote backend (the seam for pushing the same schema to a server, not yet implemented). Returns the number of errors encountered while gathering the model.
Generate a PlantUML state-machine diagram from the AST and write it to output_file.
Translate the SBDL element model into a SysML v2 textual-notation document and write it to output_file.
The mapping mirrors the SBDL type/element distinction: SBDL customtypes become SysML v2 definitions (part/requirement/action/... def, keyword chosen from the custom type's resolved base), and SBDL elements become usages typed by their custom type where they have one. Aspects/definitions/ realisations/groups are parts, requirements (and FMEA elements) are requirements, functions and events are actions, states are states, use cases and interfaces map directly, and tests are verification cases.
The translation favours persistent model constructs (everything survives parsing, unlike '//' notes):
- descriptions become 'doc' (Documentation) elements;
- provenance (the originating SBDL type and source location) becomes a 'comment' (Comment) element;
- numeric FMEA ratings become attributes;
- a function's ordered events -- and, recursively, each event's child events -- are invoked as action steps ('first start; then perform ...;'), so multi-level sequences are preserved without producing unreferenced action definitions;
- states and transitions are collected into a single 'state def' state machine (states as nested usages), with each transition rendered as 'transition ... first ... accept ... then ...';
- a requirement and its aspect become a 'satisfy' relation;
- every other typed relation (FMEA cross-links, test coverage, conditional alternatives, generic 'related' and structural parent links) becomes a typed KerML 'dependency' whose name encodes the SBDL relation type.
SBDL conditions are free text rather than valid SysML v2 boolean expressions, so conditional events keep their condition as documentation (and their alternatives as dependencies) instead of fabricating unresolvable decision guards. SBDL identifiers are rendered as SysML v2 unrestricted (single-quoted) names so ids containing ':', '-', '.' or '::' remain valid, and all elements live in a single package for simple name resolution. Returns the number of errors encountered while gathering the model.
Render a Jinja2 or Office template (txt/docx/xlsx) with AST data and write the result to output_file.
Generate a PlantUML use-case diagram from the AST and write it to output_file.
Write the full AST as a YAML document to output_file.