def addToken(self, prefix: str, s: str, token_type: TT): token = CommonToken(type=token_type.value) token.text = prefix + s token.column = self.pos token.line = self.lineNo self.pos += len(s) self.builder.append(token)
def create(self, source, type, text, channel, start, stop, line, column): t = CommonToken(source, type, channel, start, stop) t.line = line t.column = column if text is not None: t.text = text elif self.copyText and source[1] is not None: t.text = source[1].getText(start, stop) return t
def create(self, source, type, text, channel, start, stop, line, column): t = CommonToken(source, type, channel, start, stop) t.line = line t.column = column if text is not None: t.text = text elif self.copyText and source[1] is not None: t.text = source[1].getText(start,stop) return t
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): t = CommonToken(source=(recognizer, recognizer._input), type=Token.INVALID_TYPE, channel=Token.DEFAULT_CHANNEL, start=recognizer._tokenStartCharIndex, stop=recognizer._tokenStartCharIndex) t.line = recognizer._tokenStartLine t.column = recognizer._tokenStartColumn recognizer._type = Token.MIN_USER_TOKEN_TYPE recognizer.emitToken(t)
def emit_type(self, token_type, channel=Token.DEFAULT_CHANNEL, text=""): char_index = self.getCharIndex() token = CommonToken(self._tokenFactorySourcePair, token_type, channel, char_index - len(text), char_index) token.line = self.line token.column = self.column token.text = text self.emitToken(token) return token