Sweeten your JavaScript
Authors:
Open Access
- 14 October 2014
- journal article
- Published by Association for Computing Machinery (ACM) in ACM SIGPLAN Notices
- Vol. 50 (2) , 35-44
Abstract
Lisp and Scheme have demonstrated the power of macros to enable programmers to evolve and craft languages. In languages with more complex syntax, macros have had less success. In part, this has been due to the difficulty in building expressive hygienic macro systems for such languages. JavaScript in particular presents unique challenges for macro systems due to ambiguities in the lexing stage that force the JavaScript lexer and parser to be intertwined. In this paper we present a novel solution to the lexing ambiguity of JavaScript that enables us to cleanly separate the JavaScript lexer and parser by recording enough history during lexing to resolve ambiguities. We give an algorithm for this solution along with a proof that it does in fact correctly resolve ambiguities in the language. Though the algorithm and proof we present is specific to JavaScript, the general technique can be applied to other languages with ambiguous grammars. With lexer and parser separated, we then implement an expressive hygienic macro system for JavaScript called sweet.js.Keywords
This publication has 20 references indexed in Scilit:
- Honu2012
- Marco: Safe, Expressive Macros for Any Language2012
- SugarJ2011
- Fortifying macrosACM SIGPLAN Notices, 2010
- Xoc, an extension-oriented compiler for systems programming2008
- OMeta2007
- Program Transformation with Stratego/XT2004
- Template meta-programming for Haskell2002
- Macros as multi-stage computations2001
- Syntactic abstraction in schemeHigher-Order and Symbolic Computation, 1993