zaach/jison — pull request #235 by RubenVerborgh (2014-08-18 16:32:33+00:00)
Title: Reduce parser file size even more

### Summary

**This pull request, together with #234, more than halves the gzipped size of generated parsers.**

### Problem

The largest part of a Jison-generated parser is its `table`: a large array containing objects with numeric keys and (arrays of) numeric values.

#234 already optimized this table by tackling those cases:

1. **repeated long numerical arrays**
_example:_ `tables = [{ 5: [1,3,4,6,7,8,15], 6: 7}, { 20: [1,3,4,6,7,8,15], 9: 8 }]`
2. **objects where all keys have the same value**
_example:_ `tables = [{ 5: [200,204], 17: [200,204], 20: [200,204], 21: [200,204] }]`

A third optimization brings down this size even more:

3. **objects where many (but not all) keys have the same value**
_example:_ `tables = [{ 5: [200, 204], 17: [200,204], 20: [200,204], 21: 37 }]`

### Solution

Extend the translation function `o` such that it also accepts additional keys:
```
var tables = [o([5, 17, 20], [200, 204], { 21: 37 })];
```
### Results

A parser I am working on benefited significantly from the new table generation function:

- **before:** **173kb** _(generated)_, **155kb** _(minified)_, **36kb** _(gzipped)_
- **optimization 1:** **138kb** _(generated)_, **112kb** _(minified)_, **36kb** _(gzipped)_
- **optimizations 1 and 2:** **91kb** _(generated)_, **71kb** _(minified)_, **19kb** _(gzipped)_
- **optimizations 1, 2 an 3:** **76kb** _(generated)_, **57kb** _(minified)_, **16kb** _(gzipped)_

The decrease from 36kb to 19kb is a **56% reduction**.