Commit 974f5aa2 authored by dgelessus's avatar dgelessus
Browse files

Convert patchfiles into a proper separate runtime library

Previously the patchfiles were copied into the source of each
generated parser, even though they are identical for all parsers and
always use a hardcoded package name. This means that all generated
parsers had conflicting classes, although in practice this was not
noticeable, because the classes were always identical.

These common files are now a proper separate library that all
generated parsers will depend on. This will fix the class name
conflicts when using more than one SableCC parser in a single project.
parent bde01e6b
......@@ -4,17 +4,17 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'signing'
project.version = '3.2.15-SNAPSHOT'
project.group = 'de.hhu.stups'
allprojects {
project.group = 'de.hhu.stups'
project.version = '3.3.0-SNAPSHOT'
project.ext.isSnapshot = project.version.endsWith("-SNAPSHOT")
}
wrapper {
gradleVersion = "6.3"
distributionType = Wrapper.DistributionType.ALL
}
final isSnapshot = project.version.endsWith("-SNAPSHOT")
sourceCompatibility = 7
targetCompatibility = 7
......
plugins {
id "java-library"
id "maven-publish"
id "signing"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
withSourcesJar()
withJavadocJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'SableCC - Stups fork (runtime library)'
description = 'This is the runtime support library for the Stups fork of SableCC. It provides common classes and interfaces used by the generated parsers at runtime.'
url = 'https://gitlab.cs.uni-duesseldorf.de/general/stups/sablecc-stups'
licenses {
license {
name = 'GNU Lesser General Public License, Version 2.1'
url = 'http://www.gnu.org/licenses/lgpl-2.1.html'
}
}
scm {
connection = 'scm:git:https://gitlab.cs.uni-duesseldorf.de/general/stups/sablecc-stups.git'
developerConnection = 'scm:git:git@gitlab.cs.uni-duesseldorf.de:general/stups/sablecc-stups.git'
url = 'https://gitlab.cs.uni-duesseldorf.de/general/stups/sablecc-stups'
}
developers {
developer {
id = 'bendisposto'
name = 'Jens Bendisposto'
email = 'jens@bendisposto.de'
}
}
}
}
}
repositories {
maven {
final releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
final snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
url isSnapshot ? snapshotsRepoUrl : releasesRepoUrl
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
credentials {
username project.ossrhUsername
password project.ossrhPassword
}
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
rootProject.name = "sablecc"
include "sablecc-runtime"
......@@ -113,33 +113,6 @@ public class SableCC {
}
}
/*
* extract additional stups-classes from .jar-file
*/
String generated = ".";
boolean found = false;
for (String p : arguments) {
if (found) {
generated = p;
break;
}
if ("-d".equals(p)) {
found = true;
}
}
String patchFolder = generated + "/de/hhu/stups/sablecc/patch";
String[] patchFiles = { "IParser", "IToken", "ITokenListContainer",
"PositionedNode", "SourcePosition", "SourcePositions",
"SourcecodeRange" };
new File(patchFolder).mkdirs();
for (String f : patchFiles) {
extractPatchFile(patchFolder, f);
}
try {
for (int i = 0; i < filename.size(); i++) {
processGrammar((String) filename.elementAt(i), d_option);
......@@ -151,74 +124,6 @@ public class SableCC {
System.exit(0);
}
private static void extractPatchFile(String patchFolder, String patchFile) {
ClassLoader loader = SableCC.class.getClassLoader();
InputStream input = loader.getResourceAsStream("patchfiles/"
+ patchFile + ".txt");
String output = "";
String outputFile = patchFolder + "/" + patchFile + ".java";
try {
output = convertStreamToString(input);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
Writer writer = null;
try {
File file = new File(outputFile);
writer = new BufferedWriter(new FileWriter(file));
writer.write(output);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}
private static String convertStreamToString(InputStream is)
throws IOException {
/*
* To convert the InputStream to String we use the Reader.read(char[]
* buffer) method. We iterate until the Reader return -1 which means
* there's no more data to read. We use the StringWriter class to
* produce the string.
*/
if (is != null) {
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
return writer.toString();
} else {
return "";
}
}
/**
* The main method for processing grammar file and generating the
* parser/lexer.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment