adobe-photoshop/generator-assets — pull request #188 by iwehrman (2014-02-05 23:56:18+00:00)
Title: Use a generated parser instead of a regular expression to parse layer names

This pull request changes the way layer names are parsed into file specifications in order to improve readability and maintainability. It also paves the way for future elaborations of the layer-name language, as requested in #38, #159 and #184.

Currently, a [big regular expression](https://github.com/adobe-photoshop/generator-assets/compare/iwehrman;real-parser#diff-7a9076d6d94e62c13d641aa71f19ae8eL177) is used to parse the layer names. It's hard to understand–for me, at least–so I replaced it with an honest-to-goodness parser, generated from a [PEG](http://en.wikipedia.org/wiki/Parsing_expression_grammar) using [PEG.js](http://pegjs.majda.cz/), which is a new dev dependency. The structure of the grammar is easy to read and understand.

The parser, which lives in `lib/parser.js`, can be regenerated using a new grunt task, `peg`. The grammar could be simpler, but, in an effort to change as little as possible outside of the parser, I've left some cruft for now in the name of compatibility. The specification of `parseLayerNames` has changed slightly; see the [JSDoc](https://github.com/adobe-photoshop/generator-assets/compare/iwehrman;real-parser#diff-7a9076d6d94e62c13d641aa71f19ae8eR164) for details.

Although all the existing unit tests pass with this new parser, I'm sure this will change the recognized language of layer names in at least some cases. My hope, though, is that having a well defined grammar will make it easier to clearly express our current understanding of the language, as well as future additions and refinements.

CC @joelrbrandt