I suspect that there might even be a mathematical proof that the answer to this is "no", but, question: Could one invent a type of php-like language (ie with some lines that evaluate code behind the scenes, and some lines that evaluate to displayed html) where it could always be properly nested? To give an example of what I'm talking about, in rails/haml
%table
%tr
%th Title
%th Content
%th Owner
%th Categories
- @posts.each do |post|
%tr
%td
the second %tr should be aligned vertically with the first (as they are siblings in the output html), but the line that begins the each block causes it to be indented one additional line. Is it possible that someone could develop some sort of of html meta-language where indentation can reflect both control structures and proper nesting, without each coming into conflict with the other? If so, does such a thing exist?
I can think of some ways. The compiler/interpreter simply needs to make some assumptions that are carefully and explicitly outlined.
For example, assume that indents for control structures are removed for interpreting page structure, then your code above would put the data %tr
at the same indentation level as the %td
. Note that this would make some of the page structure hard to read.
Another example, make the control structure syntax coexist with page structure at a given indentation level. A control structure can exist alone or after a page structure statement. This has the advantage of being readable both in terms of code and page structure.
%table
%tr
%th Title
%th Content
%th Owner
%th Categories
%tr @posts.each do |post|
%td