forked from phoedos/pmd
Handled all steps of "Adding PMD support for a new ANTLR grammar based language" except $. Generate your Parser did not succeed because combining lexer and parser grammars has issues.
This commit is contained in:
parent
cde4efb27e
commit
a82e7eff24
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser;
|
||||
import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtTopLevel;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
|
||||
/**
|
||||
* Adapter for the KotlinParser.
|
||||
*/
|
||||
public final class PmdKotlinParser extends AntlrBaseParser<KotlinNode, KtTopLevel> {
|
||||
|
||||
@Override
|
||||
protected KtTopLevel parse(final Lexer lexer, ParserTask task) {
|
||||
KotlinParser parser = new KotlinParser(new CommonTokenStream(lexer));
|
||||
return parser.topLevel().makeAstInfo(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Lexer getLexer(final CharStream source) {
|
||||
return new KotlinLexer(source);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.ast.AstVisitor;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseRule;
|
||||
|
||||
public abstract class AbstractKotlinRule extends AntlrBaseRule {
|
||||
|
||||
protected AbstractKotlinRule() {
|
||||
// inheritance constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract AstVisitor<RuleContext, ?> buildVisitor();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.kotlin.ast.PmdKotlinParser;
|
||||
|
||||
|
||||
public class KotlinHandler extends AbstractPmdLanguageVersionHandler {
|
||||
|
||||
private final String kotlinRelease;
|
||||
|
||||
public KotlinHandler(String release) {
|
||||
kotlinRelease = release;
|
||||
// check language version?
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parser getParser() {
|
||||
return new PmdKotlinParser();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin;
|
||||
|
||||
import net.sourceforge.pmd.lang.BaseLanguageModule;
|
||||
|
||||
/**
|
||||
* Language Module for Kotlin
|
||||
*/
|
||||
public class KotlinLanguageModule extends BaseLanguageModule {
|
||||
|
||||
/** The name. */
|
||||
public static final String NAME = "Kotlin";
|
||||
/** The terse name. */
|
||||
public static final String TERSE_NAME = "kotlin";
|
||||
|
||||
/**
|
||||
* Create a new instance of Kotlin Language Module.
|
||||
*/
|
||||
public KotlinLanguageModule() {
|
||||
super(NAME, null, TERSE_NAME, "kt", "ktm");
|
||||
addVersion("", new KotlinHandler("1.3"));
|
||||
addVersion("", new KotlinHandler("1.4"));
|
||||
addDefaultVersion("", new KotlinHandler("1.5"));
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AstVisitorBase;
|
||||
|
||||
/**
|
||||
* Base class for kotlin visitors.
|
||||
*/
|
||||
public abstract class KotlinVisitorBase<P, R> extends AstVisitorBase<P, R> implements KotlinVisitor<P, R> {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user