Not much going on on the JavaScript front for the past couple of days. I’ve been away at a work conference in a swanky hotel, which was nice. Came up with some very constructive things about what we build and how we organise ourselves that makes sense from a technical point of view as well as from an editorial one. Hopefully this will allow us to architect things in a way that makes more sense.
I did a little work on Heist this evening. Heist is a templating system that bears more than a passing resemblance to mason. The nice thing about mason is that it encourages you to build about your templates inside out. You generally start with the common parts of your pages and then the parts that are specific to a page. With other template systems you generally start building a page and split the common parts out into includes. This inversion of control typically results being able to remove practically all duplication within your templates.
Mason works well for static publishing (content production systems) and for dynamic applications when combined with a decent mvc framework. Out of the box, it doesn’t encourage a separation between the url that the user requests and the page that is responded with, or a separation between presentation and business logic. Mason is also Perl specific, which is why I am building a JavaScript version (actually it isn’t a straight port and it will be able to embed different languages within the template markup – including Perl). Heist will generally be used with the mvc pattern to address the url routing and separation between markup and logic issues.
Heist is about mostly written but is going to take a lot of effort to finish (one of those 80/20 things). The parser and code generator (both in JavaScript and Perl) are done. What remains is loading source and compiled templates from files and urls in the browser and on the server-side. The parser is implemented using a combination of a state machine and a collection of regular expressions (one executed for each state during the parse).
I would have liked to use a more serious parsing technology, but working in JavaScript in a web browser limits things somewhat. Using regular expressions in the Perl version will be much more efficient in Perl once I port it to 5.10. At the moment it jumps in and out of the regular expression engine as each state is reached. With 5.10 the grammar can be expressed in a single regular expression without having to continuously run different regular expressions (see this presentation on Perl 5.10 regular expressions). I guess this is much closer to the way parsing will work in Perl 6.
Heist seems pretty fast to compile templates, although I haven’t performed any measurements yet. Compilation results can easily be cached on disk or in memory (as JavaScript functions) so I am not too worried about performance.
If you want to see what Heist templates look like, see the brain dump of Heist syntax.
That’s all for now.