antlr/antlr4 — pull request #697 by sharwell (2014-09-03 21:43:22+00:00)
Title: Initial implementation of the baseContext rule option

# WORK IN PROGRESS

## Summary

This pull request implements a new `baseContext` option for rules. The option allows multiple rules to share a single generated context class, called the *base context*. Here is an example where it might be used:

```antlr
statement
: ifStatement
| switchStatement
| emptyStatement
;

statementNotEmpty
options { baseContext = statement; }
: ifStatement
| switchStatement
;
```

In this example, the parse tree for `statementNotEmpty` is identical to `statement` (including the listener and visitor behavior). The only observable difference is the `statementNotEmpty` rule is not able to match the `emptyStatement`. This includes the fact that the `getRuleIndex()` method for the tree produced by `statementNotEmpty` will be `RULE_statement`, *not* `RULE_statementNotEmpty`. The parser does still include a constant `RULE_statementNotEmpty`, since it can be used by the parser interpreter, etc.

## Status

The implementation of the feature appears to be complete, but no unit tests have been created yet (I did side-by-side comparisons of the output to ensure it was behaving properly in a number of scenarios).

* [x] Initial implementation
* [ ] Unit tests
* [x] Error message if some alternatives which produce a particular parse tree have alt labels, and some do not (extend error 122 to search across all rules with the same base context)
* [ ] Error message if `baseContext` option is assigned a value that is not another rule
* [ ] Error message if `baseContext` is assigned a rule that itself has the `baseContext` specified (no transitive assignments allowed)