Blog Post RSS ?

Blogs » JavaScript & CSS » JavaScript and domain specific languages
 

JavaScript and domain specific languages

by Simon Willison

I recently stumbled across a group of interesting JavaScript projects by Steve Yen: JavaScript Templates, TrimQuery and TrimSpreadsheet. The first is a JavaScript templating engine, similar to PHP’s Smarty. I was initially unconvinced by the wisdom of client-side templates, but Steve has a well considered blog entry in which he defends the idea in light of the increasing complexity of web applications. As an alternative to manually gluing strings together it’s likely to become a valuable tool.

TrimQuery and TrimSpreadsheet are even more interesting: the former is a SQL style data query language for interrogating JavaScript data structures, again designed to help build complex web applications, while the latter is a full Spreadsheet implementation in just 1700 lines of code.

All three projects are part of a wider exploration involving using JavaScript for domain specific languages. A domain specific language is a language which is designed to target a specific problem, such as SQL for processing relational data structures or regular expressions for matching patterns in text. Steve points out that JavaScript is well suited for implementing such mini-languages thanks to the little-used and much-maligned ‘eval’ and ‘with’ keywords. Here’s a neat example from TrimPath that uses ‘with’:

var queryLang = TrimPath.makeQueryLang(tableColumnDefinitions); with (queryLang) { stmt = SELECT(X.a.AS("Foo"), Y.ALL, FROM(X, Y), WHERE(EQ(X.a, Y.a)), ORDER_BY(Foo.ASC) ) }

Steve’s code is well written and open-source; it’s well worth exploring.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. 11 Domain Name Generators & Search Tools Picking a domain name can be a tiring task, so...
  2. Cookie-less Session Variables in JavaScript Cookies may be delicious, but they can be clumsy if...
  3. ICANN Approve International Domain Suffixes Until now, non-English computer users needed to contend with Latin-based...
  4. Truthy and Falsy: When All is Not Equal in JavaScript Anything in JavaScript can be considered to be either truthy...
  5. Will Server-Side JavaScript ever catch on? Server-side JavaScript appears to be a logical choice for web...

This post has 6 responses so far

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...