Module context

Source
Expand description

This module provides SDML to Value functions for constructing template contexts.

Note that the created context values are not intended as a direct 1:1 representation of either the published surface syntax grammar or the Rust model. The form is simplified for use in the template language using the following guidelines.

  1. Reduce layers in the model that do not add value; i.e. [Identifierin the Rust model has an innervalue` field.
  2. Where an Option<T> field is None do not add a key in the generated object.
  3. Where a Vec<T> field is_empty do not add a key in the generated object.
  4. Use the key "__type" as a discriminator where the content of an object is ambiguous, especially in arrays.
  5. Only add source_span values for major objects such as definitions, not for individual names etc.

The upshot of this is that an if statement in a template is used to check for presence of a value before you use it. The following demonstrates this pattern for optional fields and possibly empty collections.

{% if module.base_uri -%}
 *Base URI*: {{ module.base_uri }}
{%- endif %}

{% if module.annotations -%}
  {% for ann in module.annotations -%}
    {{ ann.name }}
  {%- endfor %}
{%- endif %}

Functionsยง

annotation_constraint_to_value
Convert a SDML Constraint into a context object, in the form shown as JSON below.
annotation_property_to_value
Convert a SDML AnnotationProperty into a context object, in the form shown as JSON below.
datatype_to_value
Convert a SDML DatatypeDef into a context object, in the form shown as JSON below.
entity_to_value
Convert a SDML EntityDef into a context object, in the form shown as JSON below.
enum_to_value
Convert a SDML EnumDef into a context object, in the form shown as JSON below.
event_to_value
Convert a SDML EventDef into a context object, in the form shown as JSON below.
member_to_value
Convert a SDML Member into a context object, in the form shown as JSON below.
module_to_value
Convert a SDML Module into a context object, in the form shown as JSON below.
property_to_value
Convert a SDML PropertyDef into a context object, in the form shown as JSON below.
rdf_to_value
Convert a SDML RdfDef into a context object, in the form shown as JSON below.
structure_to_value
Convert a SDML StructureDef into a context object, in the form shown as JSON below.
type_class_to_value
Convert a SDML TypeClassDef into a context object, in the form shown as JSON below.
union_to_value
Convert a SDML UnionDef into a context object, in the form shown as JSON below.
value_to_value
Convert a SDML Value into a context object, in the form shown as JSON below.