Skip to content
This repository was archived by the owner on Feb 19, 2018. It is now read-only.

Parser: Coffeescript Redux (CS2)

Andre Lewis edited this page Sep 10, 2016 · 1 revision

michaelficarra/CoffeeScriptRedux

A rewrite of the original Coffeescript parser, trying to create a cleaner code base that is much easier to add to. Work has stalled on this project and therefore it is unclear where the lack of updates and bug fixes has left them. While it is generally agreed to be a much better platform, integrating changes means also updating them to comply with the current jashkenas/Coffeescript version.

From the conversation here by lydell:

Pros

  • pegjs is super nice to work with.
  • It has a CoffeeScript AST.
  • The compiler is basically just a list of rules mapping CoffeeScript AST nodes to JavaScript AST nodes.

Cons

  • It implements features up to CoffeeScript 1.6, so there’s a bit of catching up to do there.
  • Since it hasn’t received active maintenance for some time, some of its dependencies are out-of-date. For example, pegjs, which is used for the parser (that is, a very important component ;) ) is on version 0.8.0. I remember when pegjs 0.9.0 came out. I then tried to upgrade, but failed and give up. The latest pegjs version right now is 0.10.0. Why did I fail and give up the upgrade? Because of the next point.
  • pegjs does not support parsing languages with significant indentation. Redux therefore uses a hack to get around that limitation. This is “the only (big) flaw” in Redux, IMO.
  • Because the original compiler is (as mentioned) too permissive, Redux fails to parse some people’s programs, because Redux many times have chosen more sensibly (IMO) what is allowed and what is not. And sometimes it is not even clear how the original compiler works. This is mostly about indentation, if I remember correctly.

Parser Overview

From the conversation here by lydell:

Redux: Has a preprocessor, but for a completely different reason. This is what is done:

Preprocess a string of CoffeeScript by inserting special control characters here and there. These represent INDENT and OUTDENT tokens.

Parse that string with control characters using a parser generated by PEG.js from grammar.pegcoffee. The grammar described in grammar.pegcoffee is powerful enough to handle implicit parentheses and braces.

The reason for the insertions of the control characters is because PEG.js can’t handle significant indentation.

Parser Details:

ES2013 Compliance:

ES2015 compliance:

Clone this wiki locally