We've been learning JSPs at school and it's atrocious, so I did something better.

Basically, the (Haskell) function XML.entirety takes a string representing java code (+ extensions) and returns the parsed result. The Show instance for this AST will return plain java text (using the XML class).

Main Extension: quasi-quoted XML between <% and %>. Inside the XML quotes, you can unquote Java code between {% and %}. You can alternately nest them arbitrarily deep. You can splice any Java object into the XML, or any collection of XML elements as a list of child nodes, and any Java object as an attribute value (though not keys)

public static final XML.Node hello(final String name) { return <%

Hello, {% name %}

%> }

Bonus: More concise notation for closures. The body is either a block or an expression between parenthesis, or between quasi-quotes. That way it's easy (for the parser) to find where it ends

#Integer(Integer n) => (n * n) #Integer(Integer n) => { return n * n; } #XML.Node(String name) => <%

Hello, {% name %}

%>

final XML.Node widgets = <%

{% map(getAllWidgets(), #XML.Node(Widget w) => <% {% w %} %>) %} %>;

widgets.print(response.getWriter());

Built With

Share this project:

Updates