Added Coco language

This commit is contained in:
wener 2023-03-23 11:55:16 +01:00
parent 013ada5def
commit fa1c51caef
16 changed files with 1820 additions and 1 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

59
pmd-coco/pom.xml Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>pmd-coco</artifactId>
<name>PMD Coco</name>
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/**
* Contains the Antlr grammar for Coco.
*/
package net.sourceforge.pmd.lang.coco.ast;

View File

@ -0,0 +1,20 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.coco.cpd;
import net.sourceforge.pmd.cpd.AbstractLanguage;
/**
* Language implementation for Coco.
*/
public class CocoLanguage extends AbstractLanguage {
/**
* Creates a new Coco Language instance.
*/
public CocoLanguage() {
super("Coco", "coco", new CocoTokenizer(), ".coco");
}
}

View File

@ -0,0 +1,22 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.coco.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
import net.sourceforge.pmd.lang.coco.ast.CocoLexer;
/**
* The Coco Tokenizer.
*/
public class CocoTokenizer extends AntlrTokenizer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
return new CocoLexer(charStream);
}
}

View File

@ -0,0 +1,8 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/**
* Contains Coco tokenizer and language classes.
*/
package net.sourceforge.pmd.lang.coco.cpd;

View File

@ -0,0 +1 @@
net.sourceforge.pmd.lang.coco.cpd.CocoLanguage

View File

@ -0,0 +1,39 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
import net.sourceforge.pmd.lang.coco.cpd.CocoTokenizer;
class CocoTokenizerTest extends CpdTextComparisonTest {
CocoTokenizerTest() {
super(".coco");
}
@Override
protected String getResourcePrefix() {
return "../lang/coco/cpd/testdata";
}
@Override
public Tokenizer newTokenizer(Properties properties) {
CocoTokenizer tok = new CocoTokenizer();
return tok;
}
@Test
void testAnnotatedSource() {
doTest("simple_machine");
}
@Test
void testDocstring() {
doTest("enum");
}
}

View File

@ -0,0 +1,125 @@
import unqualified ComponentDef
import unqualified ExternalTypes
import unqualified ExternalComponent
@runtime(Runtime.SingleThreaded)
component ComponentDefImpl {
val componentInst : Provided<ComponentDef>
val rExternalComponent : Required<ExternalComponent>
init() = {}
@ignoreWarning(Warning.Unreachable)
machine M {
enum CompEnum {
case Unknown
case Value1
case Value2
}
var compEnum_ : CompEnum = CompEnum.Unknown
entry() = {
setNextState(InitialState);
}
function FunctionA(inputVal : ExternalComponent.value) : Nil = {
@ignoreWarning(Warning.IncompleteMatch)
match (inputVal) {
.Scenario1 => {
if (compEnum_ == CompEnum.Value1) {
componentInst.doStuff();
setNextState(StateA);
return nil;
} else if (compEnum_ == CompEnum.Value2) {
ExternalComponent.doOtherStuff();
setNextState(StateB);
return nil;
};
},
.Scenario2 => {
if (compEnum_ == CompEnum.Value1) {
ExternalComponent.doOtherStuff();
setNextState(StateB);
return nil;
} else if (compEnum_ == CompEnum.Value2) {
componentInst.doStuff();
setNextState(StateA);
return nil;
};
},
}
abort();
}
function FunctionB(inputVal : ExternalComponent.value) : Nil = {
@ignoreWarning(Warning.IncompleteMatch)
match (inputVal) {
.Scenario1 => {
compEnum_ = CompEnum.Value1;
setNextState(StateA);
return nil;
},
.Scenario2 => {
compEnum_ = CompEnum.Value2;
setNextState(StateA);
return nil;
},
}
abort();
}
state InitialState {
assert(compEnum_ == CompEnum.Unknown)
componentInst.initialize() = {
FunctionB(ExternalComponent.doYourThing());
}
}
state StateA {
assert(compEnum_ != CompEnum.Unknown)
componentInst.run() = {
FunctionA(ExternalComponent.doYourThing());
}
componentInst.initialize() = {
FunctionB(ExternalComponent.doYourThing());
}
}
state StateB {
ExternalComponent.doOtherStuff() = {
componentInst.run();
compEnum_ = CompEnum.Unknown;
setNextState(InitialState);
}
ExternalComponent.doOtherStuffAgain() = {
ExternalComponent.process();
setNextState(StateC);
}
}
state StateC {
ExternalComponent.process() = {
componentInst.run();
compEnum_ = CompEnum.Unknown;
setNextState(InitialState);
}
ExternalComponent.processAgain() = offer {
if (compEnum_ == CompEnum.Value1) {
componentInst.doStuff();
compEnum_ = CompEnum.Value2;
setNextState(StateA);
},
if (compEnum_ == CompEnum.Value2) {
componentInst.doStuff();
compEnum_ = CompEnum.Value1;
setNextState(StateA);
},
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
import unqualified ExternalTypes
port Example_Device {
function do_something(instanceId : TypeId) : Nil
outgoing signal signal_a(instanceId : TypeId)
outgoing signal signal_b(instanceId : TypeId, errorId : ErrorId)
outgoing signal trigger()
machine M {
var num_items_ : Bounded<0, 10> = 0
val upper_bound_ : Bounded<0, 10> = 10
val lower_bound_ : Bounded<0, 10> = 0
if (num_items_ > lower_bound_)
spontaneous = {
nondet {
signal_a(_),
signal_b(_, _),
}
num_items_ = num_items_ - 1;
}
state Init {
if (num_items_ < upper_bound_) do_something(_ : TypeId) = nondet {
{
setNextState(AddItem)
},
{
trigger();
num_items_ = num_items_ + 1;
},
}
}
state AddItem {
spontaneous = {
nondet {
{
trigger();
num_items_ = num_items_ + 1;
},
}
setNextState(Init);
}
}
}
}
@runtime(.SingleThreaded)
external component Example_Device_Base {
val ExampleDevice : Required<Example_Device>
}

View File

@ -0,0 +1,244 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[import] 1 7
[unqualified] 8 19
[ExternalTypes] 20 33
L3
[port] 1 5
[Example_Device] 6 20
[{] 21 22
L4
[function] 3 11
[do_something] 12 24
[(] 24 25
[instanceId] 25 35
[:] 36 37
[TypeId] 38 44
[)] 44 45
[:] 46 47
[Nil] 48 51
L6
[outgoing] 3 11
[signal] 12 18
[signal_a] 19 27
[(] 27 28
[instanceId] 28 38
[:] 39 40
[TypeId] 41 47
[)] 47 48
L7
[outgoing] 3 11
[signal] 12 18
[signal_b] 19 27
[(] 27 28
[instanceId] 28 38
[:] 39 40
[TypeId] 41 47
[,] 47 48
[errorId] 49 56
[:] 57 58
[ErrorId] 59 66
[)] 66 67
L8
[outgoing] 3 11
[signal] 12 18
[trigger] 19 26
[(] 26 27
[)] 27 28
L11
[machine] 3 10
[M] 11 12
[{] 13 14
L12
[var] 5 8
[num_items_] 9 19
[:] 20 21
[Bounded] 22 29
[<] 29 30
[0] 30 31
[,] 31 32
[10] 33 35
[>] 35 36
[=] 37 38
[0] 39 40
L13
[val] 5 8
[upper_bound_] 9 21
[:] 22 23
[Bounded] 24 31
[<] 31 32
[0] 32 33
[,] 33 34
[10] 35 37
[>] 37 38
[=] 39 40
[10] 41 43
L14
[val] 5 8
[lower_bound_] 9 21
[:] 22 23
[Bounded] 24 31
[<] 31 32
[0] 32 33
[,] 33 34
[10] 35 37
[>] 37 38
[=] 39 40
[0] 41 42
L16
[if] 5 7
[(] 8 9
[num_items_] 9 19
[>] 20 21
[lower_bound_] 22 34
[)] 34 35
L17
[spontaneous] 5 16
[=] 17 18
[{] 19 20
L18
[nondet] 7 13
[{] 14 15
L19
[signal_a] 9 17
[(] 17 18
[_] 18 19
[)] 19 20
[,] 20 21
L20
[signal_b] 9 17
[(] 17 18
[_] 18 19
[,] 19 20
[_] 21 22
[)] 22 23
[,] 23 24
L21
[}] 7 8
L22
[num_items_] 7 17
[=] 18 19
[num_items_] 20 30
[-] 31 32
[1] 33 34
[;] 34 35
L23
[}] 5 6
L25
[state] 5 10
[Init] 11 15
[{] 16 17
L26
[if] 7 9
[(] 10 11
[num_items_] 11 21
[<] 22 23
[upper_bound_] 24 36
[)] 36 37
[do_something] 38 50
[(] 50 51
[_] 51 52
[:] 53 54
[TypeId] 55 61
[)] 61 62
[=] 63 64
[nondet] 65 71
[{] 72 73
L27
[{] 9 10
L28
[setNextState] 11 23
[(] 23 24
[AddItem] 24 31
[)] 31 32
L29
[}] 9 10
[,] 10 11
L30
[{] 9 10
L31
[trigger] 11 18
[(] 18 19
[)] 19 20
[;] 20 21
L32
[num_items_] 11 21
[=] 22 23
[num_items_] 24 34
[+] 35 36
[1] 37 38
[;] 38 39
L33
[}] 9 10
[,] 10 11
L34
[}] 7 8
L35
[}] 5 6
L37
[state] 5 10
[AddItem] 11 18
[{] 19 20
L38
[spontaneous] 7 18
[=] 19 20
[{] 21 22
L39
[nondet] 9 15
[{] 16 17
L40
[{] 11 12
L41
[trigger] 13 20
[(] 20 21
[)] 21 22
[;] 22 23
L42
[num_items_] 13 23
[=] 24 25
[num_items_] 26 36
[+] 37 38
[1] 39 40
[;] 40 41
L43
[}] 11 12
[,] 12 13
L44
[}] 9 10
L45
[setNextState] 9 21
[(] 21 22
[Init] 22 26
[)] 26 27
[;] 27 28
L46
[}] 7 8
L47
[}] 5 6
L48
[}] 3 4
L49
[}] 1 2
L51
[@] 1 2
[runtime] 2 9
[(] 9 10
[.] 10 11
[SingleThreaded] 11 25
[)] 25 26
L52
[external] 1 9
[component] 10 19
[Example_Device_Base] 20 39
[{] 40 41
L53
[val] 3 6
[ExampleDevice] 7 20
[:] 21 22
[Required] 23 31
[<] 31 32
[Example_Device] 32 46
[>] 46 47
L54
[}] 1 2
EOF

View File

@ -142,6 +142,11 @@
<type>sh</type>
<classifier>completion</classifier>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-coco</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>

View File

@ -28,7 +28,7 @@ import net.sourceforge.pmd.PMDVersion;
class BinaryDistributionIT extends AbstractBinaryDistributionTest {
private static final List<String> SUPPORTED_LANGUAGES_CPD = listOf(
"apex", "cpp", "cs", "dart", "ecmascript",
"apex", "coco", "cpp", "cs", "dart", "ecmascript",
"fortran", "gherkin", "go", "groovy", "html", "java", "jsp",
"kotlin", "lua", "matlab", "modelica", "objectivec", "perl",
"php", "plsql", "python", "ruby", "scala", "swift", "tsql",

View File

@ -1145,6 +1145,7 @@
<module>pmd-apex-jorje</module>
<module>pmd-apex</module>
<module>pmd-cli</module>
<module>pmd-coco</module>
<module>pmd-core</module>
<module>pmd-cpp</module>
<module>pmd-cs</module>