'The standard method called to automatically emit a token at the
outermost lexical rule.  The token object should point into the
char buffer start..stop.  If there is a text override in \'text\',
use that to set the token\'s text.  Override this method to emit
custom Token objects.
If you are building trees, then you should also override
Parser or TreeParser.getMissingSymbol().'

def emit(self, token=None):

    if (token is None):
        token = CommonToken(input=self.input, type=self._state.type, channel=self._state.channel, start=self._state.tokenStartCharIndex, stop=(self.getCharIndex() - 1))
        token.line = self._state.tokenStartLine
        token.text = self._state.text
        token.charPositionInLine = self._state.tokenStartCharPositionInLine
    self._state.token = token
    return token
