Metaprogramming Text Processor

Meta-level Operations


meta-operation :=  instantiation
		|  substitution
		|  selection
		|  repetition
		|  stream-generator
		|  target-value

instantiation :=  prog-id '(' [ slot-values ] ')'
substitution :=  slot-id  |  genr-name [ '(' ')' ]
selection :=  conditional { ';' conditional } [ ':' target-value ]
repetition :=  'for' name 'in' slot-id [ 'with' target-value ] target-value
stream-generator :=  'generator' name [ list-value ]
target-value :=  escape-init [ target-defn ] escape-term

slot-values :=  slot-value { ',' slot-value }
slot-value := [ slot-name ]  |  [ [ slot-name ':' ] value ]
slot-id :=  slot-name { '.' slot-name }
slot-name  :=  name  "a name defined by a slot-defn"

genr-name  :=  name  "a name defined by a stream-generator"

value  :=  target-value  |  tuple-value  |  list-value
tuple-value  :=  '(' slot-values ')'
list-value  :=  '(' [ values ] ')'
values :=  value { ',' value }

progid  :=  [ incl-name '.' ] prog-name
prog-name :=  name  "a name defined by a program-defn"

conditional :=  predicate '?' target-defn

target-defn :=  target-text  |  metadefn
metadefn :=  escape-init  [ meta-operation ]  escape-term

MTP provides constructs for controlling how target-level text is derived. The instantiation of metaprogram definitions is the primary means of determining the variant content of derived text.

MetaProgram Instantiation

A metaprogram instantiation indicates a point within the output text for a metaprogram instance at which the metaprogram's body should be expanded and included.

Value Substitution

A value substitution indicates a point within the output text for a metaprogram instance at which the value of a referenced slot or generator should be included.

Value Selection

A value selection indicates a point within the output text for a metaprogram instance at which one of several alternative text fragments should be expanded and included.

Value Repetition

A value repetition indicates a point within the output text for a metaprogram instance at which zero of more concatenated instances of a text fragment should be expanded and included. The optional "with" phrase indicates what text, if any, is to be inserted to separate the end of one instance from the beginning of the next instance.

Value Stream Generator

A value stream generator describes a sequence of target values, one of which is its designated "current" value. Although technically a special form of metaprogram definition, a generator can occur only within the body of a metaprogram definition and can be referenced only within that definition and only after the point of its occurrence. Whenever a generator is encountered in expanding the metaprogram definition within which it is defined, the current value of that generator is reset to its initial value.
A generator itself, as an operation, has no substitution value. Instead, the current value of a generator is obtained and substituted into output whenever its name is referenced in a value substitution operation. If the optional (empty) parentheses are present in the reference, the value is first incremented. The initial value of an integer generator is "1"; the initial value of a list-specified generator is the first value in the list.

Notes

A stream-generator definition specifies a name which represents a changing stream of target values. The stream can be either a looping stream of defined values, specified by an associated list of target values, or a non-repeating stream of integer values whose initial value is "1".
The name of a stream-generator can be referenced within a program as if it were either the name of one of that program's parameters (the generator's name without parentheses) or the name of a separately defined 0-parameter program (the generator's name with empty parentheses). Referenced in either form, its current value is substituted in its place. When referenced as a program, however, its value is first incremented. For a list-specified generator, incrementing changes its current value to the next value in the list; when the current value is already the last value in the list, the current value is reset to be the first value in the list. For an integer generator, incrementing adds 1 to its current numeric-equivalent value (for example, incrementing a current value of "9" changes the current value to "10").
A stream-generator reference can be provided as the value of a target-typed parameter to a metaprogram instantiation. Whether referenced with or without parentheses, the value provided by the generator is fixed within the context of the resulting instantiation. It cannot be incremented from within the instantiation.
The "with" phrase of a repetition statement supports the inclusion of 'separator' text between expanded items, such as commas between each pair of items in a list.



PHS