Hygienic Macro System for JavaScript and Its Light-weight Implementation Framework

Abstract

In spite of its soundness, ease of use, and descriptive power, few hygienic macro systems have been incorporated to non-LISP programming languages. The difficulty lies in the self-describing nature of the macro system. Proposed is the design and a systematic implementation framework of hygienic macro systems for general programming languages. In addition to the standard syntax-rules macro features, our macro system incorporates handling of punctuations and keywords, introduces invisible blocks of code called phantom groups, and proposes the notion of suffix pattern to address problems due to recursive macro definitions. These features have been introduced to deal with richer syntax of general programming languages. The proposed implementation framework incorporates staged parser architecture, a parser generation technique using parsing expression grammars, and mutual conversion technique between the macro-enabled host language and Scheme that allows our macro system to delegate actual macro expansion task to a Scheme interpreter, instead of building hygienic macro expander from scratch. ExJS, our prototype implementation of a hygienic macro system for JavaScript, is implemented in less than 2,000 lines of JavaScript and Scheme, and exhibits its flexible syntactic extensibility.

DOI: 10.1145/2635648.2635653

Cite this paper

@inproceedings{Wakita2014HygienicMS, title={Hygienic Macro System for JavaScript and Its Light-weight Implementation Framework}, author={Ken Wakita and Kanako Homizu and Akira Sasaki}, booktitle={ILC}, year={2014} }