Metaprogramming Text Processor

Meta-level Statements

metastatement :=  type-defn
		|  program-defn
		|  file-inclusion
		|  instantiation

type-defn :=  'type' name type
program-defn :=  'program' name '(' [ slot-defns ] ')' target-value
file-inclusion :=  'include' [ name ] '"' file-id '"'

slot-defns :=  slot-defn { ',' slot-defn }
slot-defn :=  name [ '?' ] [ ':' type ]
file-id :=  "a standard Unix file path reference or URL"

type  :=  'text'  |  tuple-type  |  list-type  |  type-id
tuple-type  :=  '(' slot-defns ')' [ '?' ]
list-type  :=  type '*'
type-id  :=  [ incl-name '.' ] type-name
type-name :=  name  "a name defined by a type-defn"
incl-name :=  name  "a name defined by a file-inclusion"

MTP provides constructs for defining meta-level programs (metaprograms) and meta-level data types (metatypes). Metatypes and the parameters of metaprograms are defined in terms of the basic MTP target-level type, 'text', which can be composed as needed into more complex structures.

MetaProgram Definitions

A metaprogram definition describes a set of similar text fragments. Parameters associated with the definition characterize the differences among the fragments. The body of the definition defines the forms of alternative fragments. Instantiating the definition with specific parameter values produces a particular one of the fragments (see instantiation).

MetaProgram Parameters

The parameters of a metaprogram definition identify metadata values that must be provided to select among derivable text fragments. A set of parameters has the same form as a tuple metatype (that is, parenthesized and comma-separated). Each parameter has a name and a metatype associated with it and can be specified as required or optional.

MetaType Constructors

A metatype constructor defines how simple metadata can be combined into more complex forms. One of these is used whenever a collection of decisions are related sufficiently to be viewed as a single aggregate decision. Such aggregation simplifies understanding and use of an Adaptable Component.
There are two forms of metatype constructor: lists and tuples. Lists are denoted by a trailing '*' and indicate that the associated metadata is repeated as needed. Tuples are denoted by parentheses enclosing a set of element descriptors which are separated by commas. A tuple element descriptor consists of a name, a metatype, or a ":"-separated name and metatype. A '?' following or in place of the name indicates an optional element. A '?' following the closing parenthesis of a complete tuple description indicates that the tuple is a discriminated union in which values of this type contain exactly one of the described elements.

MetaType Definitions

A metatype definition is a means for giving a name to a metatype description. A metatype name is shorthand for and equivalent to the corresponding metatype description. Metatype definitions also provide a means to describe recursively defined metatypes. A metatype definition can be nested inside another metatype definition to create mutually recursive metatypes.

File Inclusion

The purpose of the file inclusion mechanism is to permit the inclusion of content from separately created files in the derivation of an instance component. An included file can contain any combination of target text and additional Adaptable Component definitions.


Every slot-defn should include either the '?' qualifier or the type qualifier. The '?' qualifier indicates that the slot is optional; its presence or absence indicates a simple binary choice. An optional slot which has an associated type supplies additional information when it is provided but none when it is omitted. Omitting the type qualifier from a slot-defn indicates that the slot has no value. Such a slot is useful only to express a binary choice (being present or absent in a literal sense).
A tuple-type which has the trailing '?' qualifier specifies tuple-values that are allowed to include a value for one and only one of the associated slots. This corresponds to the data structuring concept of a discriminated union.
When inclusion of a local file (that is, not on the MTP server) is attempted within an applet, most browsers will reject this as being a security violation against the local system and abort the applet's execution. To use file inclusion without restriction requires a applet executor that permits weaker security or it requires local use of some version of MTP.
Inclusion of the optional name in a file-inclusion establishes a name scope for contained definitions. Types and programs defined within the included file must be qualified with this name. This avoids the possibility of name conflicts among types or programs defined in different files. It also enhances traceability to the location of referenced definitions.