Skip to content
Snippets Groups Projects
Commit caa89c2a authored by René Schöne's avatar René Schöne
Browse files

Update relast-preprocessor to newest version.

parent 51cbd0ef
No related branches found
No related tags found
5 merge requests!39Version 1.1.0,!35Version 1.0.0,!17Version 0.3.2,!8Version 0.3.1,!6Update relast-preprocessor to newest version.
Showing
with 137 additions and 58 deletions
[submodule "relast-preprocessor"] [submodule "relast-preprocessor"]
path = relast-preprocessor path = relast-preprocessor
url = ../relast-preprocessor.git url = ../relast-preprocessor.git
branch = jastadd-fix-inc-param-debug branch = develop
[submodule "ragconnect.base/src/main/jastadd/mustache"]
path = ragconnect.base/src/main/jastadd/mustache
url = ../mustache
...@@ -78,7 +78,7 @@ jar { ...@@ -78,7 +78,7 @@ jar {
File preprocessorGrammar = file('../relast-preprocessor/src/main/jastadd/RelAst.relast') File preprocessorGrammar = file('../relast-preprocessor/src/main/jastadd/RelAst.relast')
File ragConnectGrammar = file('./src/main/jastadd/RagConnect.relast') File ragConnectGrammar = file('./src/main/jastadd/RagConnect.relast')
File intermediateGrammar = file('./src/main/jastadd/intermediate/MustacheNodes.relast') File intermediateGrammar = file('./src/main/jastadd/intermediate/MustacheNodes.relast')
File mustacheGrammar = file('./src/main/jastadd/mustache/Mustache.relast') File mustacheGrammar = file('../relast-preprocessor/src/main/jastadd/mustache/Mustache.relast')
task relast(type: JavaExec) { task relast(type: JavaExec) {
group = 'Build' group = 'Build'
main = "-jar" main = "-jar"
...@@ -220,3 +220,4 @@ publishing { ...@@ -220,3 +220,4 @@ publishing {
} }
publish.dependsOn jar publish.dependsOn jar
jar.dependsOn ":relast-preprocessor:jar"
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
aspect Navigation { aspect RagConnectNavigation {
// --- program --- // --- program ---
eq RagConnect.getChild().program() = getProgram(); eq RagConnect.getChild().program() = getProgram();
...@@ -12,16 +12,27 @@ aspect Navigation { ...@@ -12,16 +12,27 @@ aspect Navigation {
eq RagConnect.getChild().ragconnect() = this; eq RagConnect.getChild().ragconnect() = this;
eq MRagConnect.getChild().ragconnect() = getRagConnect(); eq MRagConnect.getChild().ragconnect() = getRagConnect();
// --- containedConnectSpecification ---
inh ConnectSpecification ASTNode.containedConnectSpecification();
eq RagConnect.getChild().containedConnectSpecification() = null;
eq MRagConnect.getChild().containedConnectSpecification() = null;
eq Document.getChild().containedConnectSpecification() = null;
eq Program.getChild().containedConnectSpecification() = null;
eq ConnectSpecification.getChild().containedConnectSpecification() = this;
// --- containedFile // --- containedFile
eq Grammar.getChild().containedFile() = null;
eq RagConnect.getChild().containedFile() = null; eq RagConnect.getChild().containedFile() = null;
eq MRagConnect.getChild().containedFile() = null; eq MRagConnect.getChild().containedFile() = null;
// --- containedFileName --- // --- containedFileName ---
eq Grammar.getChild().containedFileName() = null; // should be in PP eq ConnectSpecificationFile.containedFileName() = getFileName();
eq RagConnect.getChild().containedFileName() = null; refine Navigation eq ASTNode.containedFileName() {
eq ConnectSpecificationFile.getChild().containedFileName() = getFileName(); if (containedFile() == null) {
eq MRagConnect.getChild().containedFileName() = null; return containedConnectSpecification().containedFileName();
}
return refined();
// return containedFile().getFileName();
}
//--- allEndpointDefinitionList --- //--- allEndpointDefinitionList ---
syn List<EndpointDefinition> RagConnect.allEndpointDefinitionList() { syn List<EndpointDefinition> RagConnect.allEndpointDefinitionList() {
...@@ -128,8 +139,6 @@ aspect Navigation { ...@@ -128,8 +139,6 @@ aspect Navigation {
// --- rootTypeComponents --- // --- rootTypeComponents ---
syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents(); syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents();
// === for preprocessor === // --- isListComponent --- (defined in PP, but only on TypeComponent)
// --- isOptComponent --- syn boolean Component.isListComponent() = false;
syn boolean TypeComponent.isOptComponent() = false;
eq OptComponent.isOptComponent() = true;
} }
...@@ -206,5 +206,5 @@ aspect Navigation { ...@@ -206,5 +206,5 @@ aspect Navigation {
eq Document.getChild().program() = null; eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null; eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null; eq Document.getChild().containedFile() = null;
eq Document.getChild().containedFileName() = getFileName(); eq Document.containedFileName() = getFileName();
} }
Subproject commit c10bed0d03e3fa18b8133ce1de48de7646899615
/*.noNewLine.*
# Issue27
Regression test for failing parser when missing newline at end of specification.
receive A.Name ;
A ::= <Name:String> ;
...@@ -2,7 +2,6 @@ package org.jastadd.ragconnect.tests; ...@@ -2,7 +2,6 @@ package org.jastadd.ragconnect.tests;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jastadd.ragconnect.compiler.Compiler;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -10,14 +9,14 @@ import org.junit.jupiter.api.Test; ...@@ -10,14 +9,14 @@ import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.jastadd.ragconnect.tests.TestUtils.exec;
import static org.jastadd.ragconnect.tests.TestUtils.readFile; import static org.jastadd.ragconnect.tests.TestUtils.readFile;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
...@@ -25,8 +24,8 @@ public class Errors { ...@@ -25,8 +24,8 @@ public class Errors {
private static final Logger logger = LogManager.getLogger(Errors.class); private static final Logger logger = LogManager.getLogger(Errors.class);
private static final String FILENAME_PATTERN = "$FILENAME"; private static final String FILENAME_PATTERN = "$FILENAME";
private static final String INPUT_DIRECTORY = "./src/test/01-input/errors/"; private static final String ERROR_DIRECTORY = "errors/";
private static final String OUTPUT_DIRECTORY = "./src/test/02-after-ragconnect/errors/"; private static final String OUTPUT_DIRECTORY = TestUtils.OUTPUT_DIRECTORY_PREFIX + ERROR_DIRECTORY;
private static final String DEFAULT_GRAMMAR_NAME = "Errors"; private static final String DEFAULT_GRAMMAR_NAME = "Errors";
...@@ -48,44 +47,21 @@ public class Errors { ...@@ -48,44 +47,21 @@ public class Errors {
@SuppressWarnings("SameParameterValue") @SuppressWarnings("SameParameterValue")
private void test(String expectedName, String rootNode, String... connectNames) throws IOException { private void test(String expectedName, String rootNode, String... connectNames) throws IOException {
String grammarFile = INPUT_DIRECTORY + DEFAULT_GRAMMAR_NAME + ".relast"; String grammarFile = ERROR_DIRECTORY + DEFAULT_GRAMMAR_NAME + ".relast";
// String ragconnectFile = INPUT_DIRECTORY + name + ".connect"; List<String> connectFiles = Arrays.stream(connectNames)
String outFile = OUTPUT_DIRECTORY + expectedName + ".out"; .map(connectName -> ERROR_DIRECTORY + connectName + ".connect")
String expectedFile = INPUT_DIRECTORY + expectedName + ".expected"; .collect(Collectors.toList());
Path outPath = TestUtils.runCompiler(grammarFile, connectFiles, rootNode, ERROR_DIRECTORY, 1);
assertThat(connectNames).isNotEmpty();
try {
logger.debug("user.dir: {}", System.getProperty("user.dir"));
List<String> args = new ArrayList<>() {{
add("--o=" + OUTPUT_DIRECTORY);
add("--rootNode=" + rootNode);
add("--verbose");
add(grammarFile);
}};
for (String connectName : connectNames) {
args.add(INPUT_DIRECTORY + connectName + ".connect");
}
int returnValue = exec(Compiler.class, args.toArray(new String[0]), new File(outFile));
Assertions.assertEquals(1, returnValue, "RagConnect did not return with value 1");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
final String startOfErrorsPattern = "SEVERE: Errors:"; final String startOfErrorsPattern = "SEVERE: Errors:";
String out = readFile(outFile, Charset.defaultCharset()); String out = readFile(outPath, Charset.defaultCharset());
assertThat(out).contains(startOfErrorsPattern); assertThat(out).contains(startOfErrorsPattern);
out = out.substring(out.indexOf(startOfErrorsPattern) + 16); out = out.substring(out.indexOf(startOfErrorsPattern) + 16);
String expected = readFile(expectedFile, Charset.defaultCharset()); Path expectedPath = Paths.get(TestUtils.INPUT_DIRECTORY_PREFIX)
// if (inFiles.size() == 1) { .resolve(ERROR_DIRECTORY)
// expected = expected.replace(FILENAME_PATTERN, name + ".connect"); .resolve(expectedName + ".expected");
// } else { String expected = readFile(expectedPath, Charset.defaultCharset());
// for (int i = 0; i < inFiles.size(); i++) {
// expected = expected.replace(FILENAME_PATTERN + (i + 1), inFiles.get(i));
// }
// }
List<String> outList = Arrays.asList(out.split("\n")); List<String> outList = Arrays.asList(out.split("\n"));
Collections.sort(outList); Collections.sort(outList);
List<String> expectedList = Arrays.stream(expected.split("\n")) List<String> expectedList = Arrays.stream(expected.split("\n"))
......
package org.jastadd.ragconnect.tests;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.*;
import java.util.Collections;
/**
* Regression tests for fixed issues.
*
* @author rschoene - Initial contribution
*/
public class RegressionTests {
private static final String REGRESSION_TEST_OUTPUT_DIRECTORY = "regression-test/";
@Test
public void issue27() throws IOException {
String grammarFile = "regression-tests/issue27/Test.relast";
String connectFile = "regression-tests/issue27/Test.connect";
grammarFile = ensureNoTrailingNewLine(grammarFile);
connectFile = ensureNoTrailingNewLine(connectFile);
TestUtils.runCompiler(grammarFile, Collections.singletonList(connectFile), "A", REGRESSION_TEST_OUTPUT_DIRECTORY, 0);
}
private String ensureNoTrailingNewLine(String inputFileSuffix) throws IOException {
int dotIndex = inputFileSuffix.lastIndexOf('.');
String outFileSuffix = inputFileSuffix.substring(0, dotIndex) + ".noNewLine" + inputFileSuffix.substring(dotIndex);
Path inputPath = Paths.get(TestUtils.INPUT_DIRECTORY_PREFIX).resolve(inputFileSuffix);
Path outputPath = Paths.get(TestUtils.INPUT_DIRECTORY_PREFIX).resolve(outFileSuffix);
String content = Files.readString(inputPath);
Files.writeString(outputPath, content.stripTrailing(), StandardOpenOption.CREATE);
return outFileSuffix;
}
}
package org.jastadd.ragconnect.tests; package org.jastadd.ragconnect.tests;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jastadd.ragconnect.compiler.Compiler;
import org.junit.jupiter.api.Assertions;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
/** /**
...@@ -17,7 +26,10 @@ import static org.junit.jupiter.api.Assertions.fail; ...@@ -17,7 +26,10 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
public class TestUtils { public class TestUtils {
private static final Logger logger = LogManager.getLogger(TestUtils.class);
public static final double DELTA = 0.001d; public static final double DELTA = 0.001d;
public static final String INPUT_DIRECTORY_PREFIX = "./src/test/01-input/";
public static final String OUTPUT_DIRECTORY_PREFIX = "./src/test/02-after-ragconnect/";
public static String getMqttHost() { public static String getMqttHost() {
if (System.getenv("GITLAB_CI") != null) { if (System.getenv("GITLAB_CI") != null) {
...@@ -41,6 +53,41 @@ public class TestUtils { ...@@ -41,6 +53,41 @@ public class TestUtils {
return 1883; return 1883;
} }
public static Path runCompiler(String grammarFile, Iterable<String> connectFiles, String rootNode, String outputDirectory, int expectedReturnValue) {
assertThat(connectFiles).isNotEmpty();
Path outPath = Paths.get(OUTPUT_DIRECTORY_PREFIX)
.resolve(outputDirectory)
.resolve("Compiler.out");
ensureCreated(outPath.getParent());
try {
logger.debug("user.dir: {}", System.getProperty("user.dir"));
List<String> args = new ArrayList<>() {{
add("--o=" + OUTPUT_DIRECTORY_PREFIX + outputDirectory);
add("--rootNode=" + rootNode);
add("--verbose");
add(INPUT_DIRECTORY_PREFIX + grammarFile);
}};
connectFiles.forEach(connectFile -> args.add(INPUT_DIRECTORY_PREFIX + connectFile));
int returnValue = exec(Compiler.class, args.toArray(new String[0]), outPath.toFile());
Assertions.assertEquals(expectedReturnValue, returnValue, "RagConnect did not return with value " + expectedReturnValue);
} catch (IOException | InterruptedException e) {
fail(e);
}
return outPath;
}
private static void ensureCreated(Path directory) {
File directoryFile = directory.toFile();
if (directoryFile.exists() && directoryFile.isDirectory()) {
return;
}
assertTrue(directoryFile.mkdirs());
}
public static int exec(Class<?> klass, String[] args, File err) throws IOException, public static int exec(Class<?> klass, String[] args, File err) throws IOException,
InterruptedException { InterruptedException {
String javaHome = System.getProperty("java.home"); String javaHome = System.getProperty("java.home");
...@@ -79,9 +126,9 @@ public class TestUtils { ...@@ -79,9 +126,9 @@ public class TestUtils {
} }
} }
public static String readFile(String path, Charset encoding) public static String readFile(Path path, Charset encoding)
throws IOException { throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path)); byte[] encoded = Files.readAllBytes(path);
return new String(encoded, encoding); return new String(encoded, encoding);
} }
......
Subproject commit b538a7f709167c5f56fe65e6d9e9f02179cacaef Subproject commit 02f8e35993dc3f62ab49e94f69a6dc27170660da
pluginManagement {
plugins {
id 'org.jastadd' version '1.13.3'
}
}
rootProject.name = 'ragconnect' rootProject.name = 'ragconnect'
include 'relast-preprocessor' include 'relast-preprocessor'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment