Tour: Extensions

An important feature of Nyarna is its ability to extend existing schemas. Imagine someone else defined a schema that produces HTML, and you want to use that. However you want to produce a HTML tag that is not supported by that schema.

With extensions, you can extend that schema to support your desired tag, without changing the schema's source code. Extensions let you add types to a schema, inject these types into existing intersections, and inject processing code into the backends. Extensions also let you add additional backends that do not exist in the original schema.

By bundling schema types with processing code, Nyarna strives to achieve better modularity in its schemas than schemas in other languages, like for example XML schemas or JSON schemas, can provide.

You use the special “|=” operator when defining an extension to merge expressions into existing definitions.

The example code extends the schema we previously defined with a new type \Emph that allows us to enter italic code.

By calling the use function on the \SchemaDef, we can set the backend we want to use, and give the extensions we want to inject.