Formally, the extra instructions can be described as:
< [?] ( <tag-name> | <variable> ) <statement>
& ( <attribute-name> | <variable> ) [=] <expression> ;
? <expression> (, <expression>)* ;
(the underlined characters have to be typed as shown, sections enclosed in square brackets are optional. Elements separated by a vertical bar within parenthesis are exclusive options, elements surrounded by angle brackets are to be replaced by something corresponding to the concept. An asterisk represents a 0 or more repetition.)
Notice that the first two instructions do not take a quoted string literal as the first argument but an unquoted one. As I said, I am a lazy typist (and I'm sure I am not the only one) so I spared myself those quotes. Both element and attribute names can have hyphens and dots, which are invalid as PHP identifiers, more over, any PHP reserved word (such as if, while, function, etc.) can be used as an element or attribute name. PHT also supports XML namespaces, which is described below.
Variables can also be used and since in PHP they start with a $ sign, it is easy to tell when it's a literal or a variable. This precludes the use of complex expressions including functions that return a string value. I don't feel that the need to assemble tags on the fly is so significant and that allowing for variables would suffice for the odd case. See also validation for another reason.
The optional ?
sign in the <
statement allows for processing instructions.
Notice that a PHP page does start with a processing instruction: <?php
.
Another <?
within a processing instruction does not confuse the
parser, the trouble could
be with a closing one: ?>
, but there is none in the Pht source since the
pre-compiler generates the closing tag when reaching the end of
<statement>
.
While rewriting some of my own programs to test the pre-compiler I inadvertently put an equal sign in an attribute instruction. I figured this might be a common mistake and decided to allow for it.
In order to support XML namespaces, both the element and attribute names can be given as two parts separated by a colon:
[ (<namespace> | <variable> ) : ] (<name> | <variable> )
This colon is a separate operator so it can be surrounded by whitespace, PHT will take care that there will be no spaces around it in the XML output.
< Previous: Sample |