I am very sorry if I am posting this in the wrong list. It just looks as
the proper place to do it, after I tried unsuccessfully in the general list
in Spanish, my native language.
It appears to me that PHP is a good scripting language which is not as quite
well integrated with HTML or, in general, XML as it could be. I probably
re-invented the wheel and somebody, I'm sure, will be able to point me to
the right place, but I thought that I would like to see a couple of
additions to PHP, which could very well be implemented as a pre-compiler, in
the form of two new instructions, TAG and ATT which could also be
abbreviated to < and @.
The following piece of code show how to use them:
<p {
@align 'center';
echo 'este es el texto del párrafo';
}
Which would produce, after precompiled:
echo '<p', 'align="center"','>', 'este es el texto del párrafo', '</p>';
I omitted the trivial optimization of putting all the strings into a single
one.
So, the TAG or < instruction would be followed by a valid tag name and then
a statement. The statement, as usual, can be replaced by a statement block,
enclosed in curly braces. I don't see any need for the tag name to be
enclosed in any kind of quotes. A variable instead of a literal tag name
should also be valid. Thus:
$p = 'p';
<$p { etc. }
would do the same. This syntax would prevent functions as a source of tag
names, which would be a very rare case and taking it under consideration
would really make the whole thing too cumbersome.
The ATT (attribute) or @ instruction is to be followed by a valid attribute
name and an expression providing the value. The attribute name can be the
value of a variable, so that
$attribute = 'align';
@$attribute 'center';
Once again functions cannot be used.
Why all these?
XML is block structured, just as PHP is. It is troublesome to keep track of
two sets of blocks. Most IDEs provide a 'matching brace' lookup function,
which works fine for PHP (or other such languages) but cannot be used for
the XML (or HTML) blocks within.
I cannot imagine a well-structured program where one block structure would
fail to nest properly with the other. That is, a closed block of PHP
program should produce an equally closed block of XML output.
Basically, I don't want to keep track manually of how my XML blocks are
build.
Even a Code Beautifier would be able to handle the proper nesting of XML
(with these instructions) along PHP. The code would simply look good, and
that means it would be easy to get it right.
I would also add a declarative statement to handle XML validation. The
declaration would have a reference to a DTD or Schema that describes the XML
to be generated. Optionally, the declaration would also give an xpath
string which would indicate what part of the schema is being validated.
This would allow the declaration to be used in functions or classes where
only fragments of the full schema are being generated.
And, by the by, I wouldn't mind the precompiler to take ? as a synonym for
echo.
Just an example of a more substantial piece of code:
<table {
<tr {
<th {
@rowspan 2;
@valign "top";
// Here I am using the ? instead of echo
? 'Dirección';
}
<td {
<input {
@name 'Direccion1';
@size 50;
@value $row['Direccion1'];
}
}
}
// notice the use of curly braces is just as optional
// as anywhere else in PGP
// This might be not propper coding practice, but it's up to the coder.
<tr <td <input {
@name 'Direccion2';
@size 50;
@value $row['Direccion2'];
}
<tr {
// Same thing here. There is no need to put curly braces in the TH
and TD tags
// but it is in the previous TR and the following INPUT
<th 'Código Postal';
<td <input {
@name 'CodPos';
@value $row['CodPos'];
}
}
}
So, this is what I had in mind and, though I tried to get somewhere with
Bison and Flex, the results have not been good, it is way over my abilities.
Thus, I though that the guys in this list have to know way more than I do
and might be interested.
Cheers
Satyam