JavaScript domain-specific language syntax-hack

This is an interesting idea: using the JavaScript ‘with’ keyword, you can hack up a syntax for an embedded DSL pretty easily. Even if I had known about the ‘with’ keyword :-), I might not have thought of that. Although I actually did do something like that in Python before, using a string of Python code and eval, which is actually the same thing but harder.

Now, the syntax you get here isn’t perfect; the extra commas and stuff aren’t that cool. However, it’s neat to see that such a simple idea can get you so close to having well-integrated embedded DSLs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.