| 1 | Template data model |
|---|
| 2 | ------------------- |
|---|
| 3 | |
|---|
| 4 | A template is always interpreted in the context of a data model, |
|---|
| 5 | provided by the part of Alue that is using the template. |
|---|
| 6 | |
|---|
| 7 | A data model consists of a set of ATTRIBUTES. An attribute has a name |
|---|
| 8 | (which follows the lexical syntax of an identifier, as specified |
|---|
| 9 | below) and a value. |
|---|
| 10 | |
|---|
| 11 | There are several kinds of attribute values: |
|---|
| 12 | |
|---|
| 13 | â literal strings |
|---|
| 14 | |
|---|
| 15 | - a list of values |
|---|
| 16 | |
|---|
| 17 | - a structured value, which is simply a data (sub)model |
|---|
| 18 | |
|---|
| 19 | - a definition closure (described later) |
|---|
| 20 | |
|---|
| 21 | An attribute value may also be specifically missing. |
|---|
| 22 | |
|---|
| 23 | Typically, the part of Alue that uses the template defines a data |
|---|
| 24 | model schema, which describes the names and value kinds (including the |
|---|
| 25 | schemas of any submodels) of attributes. |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | Lexical considerations |
|---|
| 29 | ---------------------- |
|---|
| 30 | |
|---|
| 31 | The template language is modeful. The two modes are LITERAL and |
|---|
| 32 | DIRECTIVE. All template files start in the LITERAL mode. |
|---|
| 33 | |
|---|
| 34 | In either mode, the dollar sign ($) may be used to switch modes. |
|---|
| 35 | |
|---|
| 36 | In either mode, a hash sign (#) starts a comment that extends to the |
|---|
| 37 | end of the line. The end-of-line is considered a part of the comment. |
|---|
| 38 | |
|---|
| 39 | In LITERAL mode, most characters (including whitespace) stand for |
|---|
| 40 | themselves and are copied verbatim to the output. The exceptions are |
|---|
| 41 | the curly brackets ({}), which are used for grouping, and the |
|---|
| 42 | mode-switching dollar sign. |
|---|
| 43 | |
|---|
| 44 | In the DIRECTIVE mode, input is tokenized in the manner customary for |
|---|
| 45 | computer languages: |
|---|
| 46 | |
|---|
| 47 | - Whitespace is ignored, except so far as it is used to separate tokens. |
|---|
| 48 | |
|---|
| 49 | - Punctuation tokens are the ordinary parentheses (()), and the comma (,). |
|---|
| 50 | |
|---|
| 51 | â Names are nonempty sequences of the ASCII letters ('a' to 'z' in |
|---|
| 52 | either case), ASCII decimal digits ('0' to '9'), the dash (-), the |
|---|
| 53 | period (.) and the underscore (_). |
|---|
| 54 | |
|---|
| 55 | â The following names are reserved for use as syntactic keywords: |
|---|
| 56 | def, else, for, if, in, include. Other names are called |
|---|
| 57 | identifiers. |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | Template syntax |
|---|
| 61 | --------------- |
|---|
| 62 | |
|---|
| 63 | Curly brackets (in LITERAL mode) are used to delimit a TEMPLATE LIST. |
|---|
| 64 | A template list consists of literal text and directives. When |
|---|
| 65 | occurring alone, a template list is processed as if the surrounding |
|---|
| 66 | curly brackets were missing, but in certain directives a template list |
|---|
| 67 | is saved (uninterpreted) for later use. |
|---|
| 68 | |
|---|
| 69 | An ATTRIBUTE REFERENCE consists of an identifier by itself. Since |
|---|
| 70 | identifiers are only recognized in DIRECTIVE mode, an attribute |
|---|
| 71 | reference is most commonly surrounded by dollar signs ($foo$). If the |
|---|
| 72 | value of the attribute is a literal string, that string is outputted. |
|---|
| 73 | |
|---|
| 74 | For example, if there is an attribute called "foo" whose value is |
|---|
| 75 | the literal string "cat", then $foo$ will output "cat". |
|---|
| 76 | |
|---|
| 77 | A LIST ITERATION consists of an identifier followed by a template |
|---|
| 78 | list. If the value of the attribute is a list (or a structured value, |
|---|
| 79 | which is treated as a one-element list), then the template list will |
|---|
| 80 | be interpreted once for each element of the value list. The element |
|---|
| 81 | will be accessible inside the template list as the attribute named |
|---|
| 82 | "cursor", and if the element is a structured value, all its attributes |
|---|
| 83 | are also available inside the list. |
|---|
| 84 | |
|---|
| 85 | For example, if the attribute called "nephews" contains as its value |
|---|
| 86 | a list of the literal strings "Huey", "Dewey", and "Louie", then |
|---|
| 87 | $nephews${$cursor$! } will output "Huey! Dewey! Louie! ". Note that |
|---|
| 88 | there must be no whitespace in the "${" pair. |
|---|
| 89 | |
|---|
| 90 | A CONDITIONAL consists of the keyword "if" followed by an identifier, |
|---|
| 91 | followed by a template list, and optionally followed by the keyword |
|---|
| 92 | "else" and another template list. If the identifier names an |
|---|
| 93 | attribute that has a value, then the first template list is |
|---|
| 94 | interpreted. if there is no attribute named by the identifier, the |
|---|
| 95 | the second template list (if any) is interpreted. |
|---|
| 96 | |
|---|
| 97 | For example, consider $if foo${yes}$else${no}$. If there is an |
|---|
| 98 | attribute called "foo", then "yes" is outputted; otherwise, "no" is |
|---|
| 99 | outputted. |
|---|
| 100 | |
|---|
| 101 | Note that there must not be any spaces in the "${" and "}$" pairs. |
|---|
| 102 | However, there may be whitespace between the dollar signs and the |
|---|
| 103 | keywords (thus, "$ if" is allowed). |
|---|
| 104 | |
|---|
| 105 | A DEFINITION consists of |
|---|
| 106 | - the keyword "def", followed by |
|---|
| 107 | - an identifier (the definee), followed by |
|---|
| 108 | - an ordinary opening parenthesis "(", followed by |
|---|
| 109 | - a comma-separated list of identifiers (the parameters), followed by |
|---|
| 110 | - an ordinary closing parenthesis ")", followed by |
|---|
| 111 | - a template list (the body). |
|---|
| 112 | The definition does not output anything. However, the definee may |
|---|
| 113 | subsequently be used in an invocation, discussed below. A definition |
|---|
| 114 | may be (and usually is) recursive. |
|---|
| 115 | |
|---|
| 116 | An INVOCATION consists of |
|---|
| 117 | - an identifier (the invokee), followed by |
|---|
| 118 | - an ordinary opening parentesis "(", followed by |
|---|
| 119 | - a comma-separated list of identifiers (the arguments), followed by |
|---|
| 120 | - an ordinary closing parenthesis ")". |
|---|
| 121 | If there is no usable definee that matches the invokee, or the number |
|---|
| 122 | of parameters disagrees with the number of arguments, the invocation |
|---|
| 123 | outputs nothing. Otherwise, the body of the corresponding definition |
|---|
| 124 | will be interpreted, with each parameter standing for the |
|---|
| 125 | corresponding argument. |
|---|
| 126 | |
|---|
| 127 | For example, consider the following template: |
|---|
| 128 | $def twice(a)${$a$$a$} $twice(foo)$ |
|---|
| 129 | Now, if "foo" is an attribute having as its value the literal string |
|---|
| 130 | "me", then this template outputs " meme". |
|---|
| 131 | |
|---|
| 132 | Note: as usual, the sequences "${" and "}$" may not contain any |
|---|
| 133 | whitespace. The one space before "meme" in the output results from |
|---|
| 134 | the space separating the definition and the invocation (which is not |
|---|
| 135 | mandatory by no means). |
|---|