use of apex.jorje.parser.impl.ApexLexer in project pmd by pmd.
the class ApexLexerTest method testParser.
@Test
public void testParser() throws Exception {
CharStream in = new ANTLRStringStream(CODE);
ApexLexer lexer = new ApexLexer(in);
ApexParser parser = new ApexParser(new CommonTokenStream(lexer));
CompilationUnit compilationUnit = parser.compilationUnit();
Assert.assertNotNull(compilationUnit);
}
use of apex.jorje.parser.impl.ApexLexer in project pmd by pmd.
the class ApexTokenizer method tokenize.
@Override
public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
StringBuilder code = sourceCode.getCodeBuffer();
ANTLRStringStream ass = new ANTLRStringStream(code.toString());
ApexLexer lexer = new ApexLexer(ass) {
public void emitErrorMessage(String msg) {
throw new TokenMgrError(msg, TokenMgrError.LEXICAL_ERROR);
}
};
try {
Token token = lexer.nextToken();
while (token.getType() != Token.EOF) {
if (token.getChannel() != Lexer.HIDDEN) {
String tokenText = token.getText();
if (!caseSensitive) {
tokenText = tokenText.toLowerCase(Locale.ROOT);
}
TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine());
tokenEntries.add(tokenEntry);
}
token = lexer.nextToken();
}
} finally {
tokenEntries.add(TokenEntry.getEOF());
}
}
use of apex.jorje.parser.impl.ApexLexer in project pmd by pmd.
the class ApexLexerTest method testLexer.
@Test
public void testLexer() throws Exception {
CharStream in = new ANTLRStringStream(CODE);
ApexLexer lexer = new ApexLexer(in);
Token token = lexer.nextToken();
int tokenCount = 0;
while (token.getType() != Token.EOF) {
tokenCount++;
token = lexer.nextToken();
}
Assert.assertEquals(43, tokenCount);
}
Aggregations