use of net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer in project pmd by pmd.
the class SwiftTokenizer method tokenize.
@Override
public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
StringBuilder buffer = sourceCode.getCodeBuffer();
try {
ANTLRInputStream ais = new ANTLRInputStream(buffer.toString());
SwiftLexer lexer = new SwiftLexer(ais);
lexer.removeErrorListeners();
lexer.addErrorListener(new ErrorHandler());
Token token = lexer.nextToken();
while (token.getType() != Token.EOF) {
if (token.getChannel() != Lexer.HIDDEN) {
TokenEntry tokenEntry = new TokenEntry(token.getText(), sourceCode.getFileName(), token.getLine());
tokenEntries.add(tokenEntry);
}
token = lexer.nextToken();
}
} catch (ANTLRSyntaxError err) {
// option
throw new TokenMgrError("Lexical error in file " + sourceCode.getFileName() + " at line " + err.getLine() + ", column " + err.getColumn() + ". Encountered: " + err.getMessage(), TokenMgrError.LEXICAL_ERROR);
} finally {
tokenEntries.add(TokenEntry.getEOF());
}
}
Aggregations