Search in sources :

Example 1 with ApexLexer

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);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CompilationUnit(apex.jorje.data.ast.CompilationUnit) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ApexLexer(apex.jorje.parser.impl.ApexLexer) ApexParser(apex.jorje.parser.impl.ApexParser) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 2 with ApexLexer

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());
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ApexLexer(apex.jorje.parser.impl.ApexLexer) TokenMgrError(net.sourceforge.pmd.lang.ast.TokenMgrError) Token(org.antlr.runtime.Token)

Example 3 with ApexLexer

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);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ApexLexer(apex.jorje.parser.impl.ApexLexer) Token(org.antlr.runtime.Token) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Aggregations

ApexLexer (apex.jorje.parser.impl.ApexLexer)3 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)3 CharStream (org.antlr.runtime.CharStream)2 Token (org.antlr.runtime.Token)2 Test (org.junit.Test)2 CompilationUnit (apex.jorje.data.ast.CompilationUnit)1 ApexParser (apex.jorje.parser.impl.ApexParser)1 TokenMgrError (net.sourceforge.pmd.lang.ast.TokenMgrError)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1