forked from phoedos/pmd
Add CPD support for antlr based grammar on Golang
This commit is contained in:
@ -12,6 +12,10 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
@ -24,6 +28,10 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
|
1317
pmd-go/src/main/antlr4/net.sourceforge.pmd.lang.go.antlr4/Golang.g4
Normal file
1317
pmd-go/src/main/antlr4/net.sourceforge.pmd.lang.go.antlr4/Golang.g4
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,29 +4,20 @@
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.go.antlr4.GolangLexer;
|
||||
|
||||
|
||||
/**
|
||||
* Implements a tokenizer for the Go Language.
|
||||
*
|
||||
* @author oinume@gmail.com
|
||||
* The Go tokenizer.
|
||||
*/
|
||||
public class GoTokenizer extends AbstractTokenizer {
|
||||
public class GoTokenizer extends AntlrTokenizer {
|
||||
|
||||
/**
|
||||
* Creates a new {@link GoTokenizer}
|
||||
*/
|
||||
public GoTokenizer() {
|
||||
// setting markers for "string" in Go
|
||||
this.stringToken = new ArrayList<String>();
|
||||
this.stringToken.add("\"");
|
||||
this.stringToken.add("`");
|
||||
|
||||
// setting markers for 'ignorable character' in Go
|
||||
this.ignorableCharacter = new ArrayList<String>();
|
||||
this.ignorableCharacter.add(";");
|
||||
|
||||
// setting markers for 'ignorable string' in Go
|
||||
this.ignorableStmt = new ArrayList<String>();
|
||||
@Override
|
||||
protected AntlrTokenManager getLexerForSource(SourceCode sourceCode) {
|
||||
CharStream charStream = AntlrTokenizer.getCharStreamFromSourceCode(sourceCode);
|
||||
return new AntlrTokenManager(new GolangLexer(charStream), sourceCode.getFileName());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.go;
|
||||
|
||||
import net.sourceforge.pmd.lang.BaseLanguageModule;
|
||||
|
||||
/**
|
||||
* Language Module for Go.
|
||||
*/
|
||||
public class GoLanguageModule extends BaseLanguageModule {
|
||||
|
||||
/** The name. */
|
||||
public static final String NAME = "Golang";
|
||||
/** The terse name. */
|
||||
public static final String TERSE_NAME = "go";
|
||||
|
||||
/**
|
||||
* Create a new instance of Swift Language Module.
|
||||
*/
|
||||
public GoLanguageModule() {
|
||||
super(NAME, null, TERSE_NAME, null, "go");
|
||||
addVersion("", null, true);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
net.sourceforge.pmd.lang.go.GoLanguageModule
|
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.go.GoLanguageModule;
|
||||
|
||||
|
||||
|
||||
public class LanguageVersionTest extends AbstractLanguageVersionTest {
|
||||
|
||||
public LanguageVersionTest(String name, String terseName, String version, LanguageVersion expected) {
|
||||
super(name, terseName, version, expected);
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] { { GoLanguageModule.NAME, GoLanguageModule.TERSE_NAME, "",
|
||||
LanguageRegistry.getLanguage(GoLanguageModule.NAME).getDefaultVersion(), }, });
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
|
||||
|
||||
public class GoTokenizerTest extends AbstractTokenizerTest {
|
||||
|
||||
private static final String FILENAME = "btrfs.go";
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void buildTokenizer() throws IOException {
|
||||
this.tokenizer = new GoTokenizer();
|
||||
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSampleCode() throws IOException {
|
||||
return IOUtils.toString(GoTokenizer.class.getResourceAsStream(FILENAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenizeTest() throws IOException {
|
||||
this.expectedTokenCount = 3517;
|
||||
super.tokenizeTest();
|
||||
}
|
||||
}
|
692
pmd-go/src/test/resources/net/sourceforge/pmd/cpd/btrfs.go
Normal file
692
pmd-go/src/test/resources/net/sourceforge/pmd/cpd/btrfs.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user