Although, both lexer and parser grammars can have a custom super
class set, but only the generated parser sources were prepared to
import these classes. The patch makes custom lexer ancestor
classes imported, too.
Until now, the generated Python3 code imported the custom parser
superclasses relatively. However, this only worked in Python3 if
the module was inside a package, since relative imports rely on
__name__ to determine the current module's position in the package
hierarchy. In case of a standalone script, this was always __main__
and hence these relative imports failed.
The patch handles this issue them same way as it is handled by
listener imports.
Change to support import of lexer grammars containing modes into other
lexer grammars. The semantics for this are,
* sets of channels from all grammars are merged
* rules of modes found in an imported grammar which are in the root
grammar are merged into the root grammar mode.
* modes which are not in the root grammar are added to the root
grammar, excluding modes which become empty due to a re-definition of
rules in the root grammar.
Add an accessLevel parser option. Use this to specify the access level
(public, etc) used on the classes and protocols in the generated
parser / lexer / listeners. This required adding the option to
tool.Grammar.parserOptions so that it was known as a valid option, and
to codegen.model.{Recognizer,ListenerFile,VisitorFile} so that it was
available to the template in all the necessary contexts.
The Swift template has been extended to recognize this option, and generate
classes and members using "open", "public" or "internal" as appropriate.
This is only fully implemented for Swift. The option is generic, but
the language-specific templates will need to be updated for any language
that would like similar support.
Closes#1597.