Please read before answering. This is a fantasy programming technique I'm dreaming up. I want to know if there's anything close in real life.
The following JSP page:
<%
html {
head {
title {"Pure fantasy";}
}
body {
h1 {"A heading with double quote (\") character";}
p {"a paragraph";}
String s = "a paragraph in string. the date is ";
p {
s;
new Date().toString();
}
table (Border.ZERO, new Padding(27)) {
tr {
for (int i = 0; i < 10; i++) {
td {i;}
}
}
}
}
}
%>
could generate the following HTML page:
<html>
<head>
<title>Pure fantasy</title>
</head>
<body>
<h1>A heading with double quote (") character</h1>
<p>a paragraph</p>
<p>a paragraph in string. the date is 11 December 2012</p>
<table border="0" padding="27">
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</body>
</html>
The thing about this fantasy is it reuses the same old Java programming language technique that enable customized keywords used in a way similar to if-else-then, while, try-catch etc to represent html tags in a non-html way that can easily be checked for syntactic correctness, and most importantly can easily be mixed up with regular Java code without being lost in a sea of <%, %>, <%=, out.write(), etc.
An added feature is that strings can directly be placed as commands to print out into generated HTML, something Java doesn't support (where pure strings have to be assigned to variables before use).
Is there anything in real life that comes close?
If not, is it possible to define customized keywords in Java or JSP?
Or do I have to create an entirely new programming language for that?
What problems do you see with this kind of setup?
PS: I know you can use HTML libraries to construct HTML using Java code, but the problem with such libraries is, the source code itself doesn't have a readable HTML representation like the code above does - if you get what I mean.