Commit 8dcedcbe authored by Victor Marsault's avatar Victor Marsault

Initial meaningful commit.

parent 95428389
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
......@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
cyphsem
Copyright (C) 2019 Victor Marsault
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
cyphsem Copyright (C) 2019 Victor Marsault
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
......@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
# cyphsem
Requirement :
- Java 10
- Maven 3.5.2+
Compile with:
$ mvn compile
Launch test suite with:
$ mvn test
Produce doc with:
$ mvn javadoc:javadoc
/* CyphSem
Copyright (c) 2018,2019 Victor Marsault
This file is part of CyphSem.
CyphSem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CyphSem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CyphSem. If not, see <https://www.gnu.org/licenses/>. */
#!/bin/bash
tmpfile=$(mktemp)
cat misc/header.txt $1 > ${tmpfile}
mv ${tmpfile} $1
<!--
CyphSem
Copyright (c) 2018,2019 Victor Marsault
This file is part of CyphSem.
CyphSem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CyphSem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CyphSem. If not, see https://www.gnu.org/licenses/. -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.ac.ed.cyphsem</groupId>
<artifactId>cyphsem</artifactId>
<packaging>jar</packaging>
<version>0.4.1-SNAPSHOT</version>
<name>cyphsem</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.6.2</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.package>uk.ac.ed.cyphsem.language.parser.autogen</antlr4.package>
<antlr4.visitor>false</antlr4.visitor>
<antlr4.listener>false</antlr4.listener>
</properties>
<build>
<plugins>
<!-- ## Execution ######################################################### -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>cyphsem-executor-${project.version}</finalName>
<archive>
<manifest>
<mainClass>
uk.ac.ed.cyphsem.cli.Executor
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<classifier>cyphsem-execute</classifier>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<!-- ## ANTLR ############################################################# -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ## Sets up surefire plugin to keep more info ######################### -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<!--
<trimStackTrace>false</trimStackTrace>
-->
<!--
<testFailureIgnore>true</testFailureIgnore>
-->
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
</plugin>
<!-- ## JAVADOC ############################################################ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<stylesheetfile>${basedir}/src/main/javadoc/stylesheet.css</stylesheetfile>
<quiet>true</quiet>
<show>private</show>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<charset>UTF-8</charset>
<isOffline>false</isOffline>
<links>
<link>http://www.antlr.org/api/Java</link>
<link>https://neo4j.com/docs/api/java-driver/current</link>
</links>
<tags>
<tag>
<name>fordev</name>
<placement>a</placement>
<head>Note to developpers</head>
</tag><tag>
<name>beware</name>
<placement>a</placement>
<head>Beware</head>
</tag>
</tags>
</configuration>
</plugin>
<!-- ## GPG AUTOSIGN ####################################################### -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keyname>3C2589DAE0AC2F777896DDB4AF7B03CB6A5C6E07</keyname>
</configuration>
</plugin>
<!-- ## JACOCO ############################################################# -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<excludes>
<!-- exclude autogen package from report -->
<exclude>uk/ac/ed/cyphsem/parser/autogen/*.*</exclude>
</excludes>
</configuration>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}
<!--${project.build.directory}/coverage-reports/jacoco-ut.exec-->
</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.ut.execution.data.file}
<!--${project.build.directory}/coverage-reports/jacoco-ut.exec-->
</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/* CyphSem
Copyright (c) 2018,2019 Victor Marsault
This file is part of CyphSem.
CyphSem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CyphSem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CyphSem. If not, see <https://www.gnu.org/licenses/>. */
package uk.ac.ed.cyphsem;
import java.util.LinkedList;
import java.util.Deque;
import java.util.Optional;
import java.util.EnumSet;
public class Interruptor {
public static enum Issue {
NON_DETERMINISM;
}
private boolean _interrupted = false ;
private Deque<String> _warningMessages = new LinkedList<String>();
private EnumSet<Issue> _issues = EnumSet.noneOf(Issue.class);
public synchronized void interrupt()
{ _interrupted = true; }
public synchronized void check() throws InterruptedException {
if (_interrupted)
throw (new InterruptedException());
}
public void pushWarning(String message)
{ _warningMessages.offer(message); }
public void pushWarning(String message, Issue... issues)
{
for (Issue issue: issues)
_issues.add(issue);
pushWarning(message);
}
public String warning() { return _warningMessages.poll(); }
public boolean hasWarning() { return _warningMessages.isEmpty(); }
}
/* CyphSem
Copyright (c) 2018,2019 Victor Marsault
This file is part of CyphSem.
CyphSem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CyphSem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CyphSem. If not, see <https://www.gnu.org/licenses/>. */
package uk.ac.ed.cyphsem;
import uk.ac.ed.cyphsem.Parameters.*;
import uk.ac.ed.cyphsem.utils.*;
import java.util.NoSuchElementException;
import java.lang.IllegalArgumentException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.function.Supplier;
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.Function;
/** This class implements the dynamic parameters for semantics.
* Static field {@link #global} gives the current global instance of parameters
* to be used during computation.
***/
public class Parameters {
public final static Parameters global = new Parameters();
public static Parameters make() { return new Parameters(); }
private static final Map<String, ParameterGetterSetter<? extends Enum<?>>> map
= new HashMap<>();
// private static interface EnumBuilder<T> {
// default T
// }
private static class ParameterGetterSetter<T extends Enum<T>>
{
Class<T> enumClass;
Function<Parameters,T> supplier;
BiConsumer<Parameters, T> consumer;
public T get(Parameters p) { return supplier.apply(p); }
public void setParameter(Parameters p, String value) {
String uppercase_value = value.toUpperCase();
try { consumer.accept (p, Enum.valueOf(enumClass, uppercase_value)); }
catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Value "+ value +", implicitly rewritten as " + uppercase_value
+ ", does not define a proper instance of enum " + enumClass.getCanonicalName() + "."
+" Acceptable values are : " + StringOf.iterable(Arrays.asList(enumClass.getEnumConstants()),"","",", ") + ".");
}
}
private ParameterGetterSetter
(Class<T> c, Function<Parameters, T> supplier, BiConsumer<Parameters, T> consumer)
{
this.enumClass = c;
this.supplier = supplier;
this.consumer = consumer;
}
}
public static enum MergeVersion {
LEGACY,
ATOMIC,
GROUPING,
COLLAPSE,
AGGRESSIVE;
}
private MergeVersion merge = MergeVersion.AGGRESSIVE;
public MergeVersion merge() { return merge; }
static {
map.put("merge",
new ParameterGetterSetter<MergeVersion>(
MergeVersion.class,
( p -> p.merge ),
( (p,a) -> p.merge = a )
)
);
}
public static enum EqualityVersion {
PERMISSIVE,
STRICT;
}
private EqualityVersion equality = EqualityVersion.PERMISSIVE;
static {
map.put("equality",
new ParameterGetterSetter<EqualityVersion>(
EqualityVersion.class,
p -> p.equality,
(p,a) -> p.equality = a));
}
public static enum SetVersion {
LEGACY,
PERMISSIVE,
STRICT;
}
private SetVersion set = SetVersion.STRICT;
static {
map.put("set",
new ParameterGetterSetter<SetVersion>(
SetVersion.class,
( p -> p.set ),
(p,a) -> p.set = a
));
}
public static enum DeleteVersion {
LEGACY,
AMNESIC,
TOMBSTONE;
}
private DeleteVersion delete = DeleteVersion.TOMBSTONE;
static {
map.put("delete",
new ParameterGetterSetter<DeleteVersion>(
DeleteVersion.class,
p -> p.delete,
(p,a) -> p.delete = a
));
}
public void setParameter(String key, String value)
throws IllegalArgumentException
{ getGetterSetter(key).setParameter(this,value); }
@SuppressWarnings("rawtypes")
private static ParameterGetterSetter getGetterSetter(String key)
throws IllegalArgumentException
{
if (map.containsKey(key))
return map.get(key);
else
throw new IllegalArgumentException("Parameter "+key+" does not exists");
}
private Enum<?> get(String key) {
return getGetterSetter(key).get(this);
}
public EqualityVersion equality() { return equality; }
public SetVersion set() { return set; }
public DeleteVersion delete() { return delete; }
public Set<String> allParams() { return map.keySet(); }
public String toString() {
String res = "{";
String sep = "";
for (String param : allParams())
{
res += sep + param + "=" + get(param);
sep = ", ";
}
res+= "}";
return res;
}
}
/* CyphSem
Copyright (c) 2018,2019 Victor Marsault
This file is part of CyphSem.
CyphSem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CyphSem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CyphSem. If not, see <https://www.gnu.org/licenses/>. */
package uk.ac.ed.cyphsem;
import uk.ac.ed.cyphsem.*;
import uk.ac.ed.cyphsem.Parameters.*;
import uk.ac.ed.cyphsem.Parameters.MergeVersion.*;