forked from jasder/antlr
Ensure file paths passed to STGroup[File] are absolute
- gracefully handle grammars without source fileNames
This commit is contained in:
parent
6ffc59d63c
commit
8ce79eec81
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
<artifactId>oss-parent</artifactId>
|
||||
<version>9</version>
|
||||
</parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<groupId>solussd</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<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>
|
||||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<groupId>solussd</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<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>
|
||||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<groupId>solussd</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>ST4</artifactId>
|
||||
<version>4.0.8</version>
|
||||
<version>4.0.9-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.abego.treelayout</groupId>
|
||||
|
|
|
@ -838,7 +838,7 @@ public class Tool {
|
|||
// or just or the relative path recorded for the parent grammar. This means
|
||||
// that when we write the tokens files, or the .java files for imported grammars
|
||||
// taht we will write them in the correct place.
|
||||
if (fileNameWithPath.lastIndexOf(File.separatorChar) == -1) {
|
||||
if ((fileNameWithPath == null) || (fileNameWithPath.lastIndexOf(File.separatorChar) == -1)) {
|
||||
// No path is included in the file name, so make the file
|
||||
// directory the same as the parent grammar (which might sitll be just ""
|
||||
// but when it is not, we will write the file in the correct place.
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.stringtemplate.v4.STGroupFile;
|
|||
import org.stringtemplate.v4.StringRenderer;
|
||||
import org.stringtemplate.v4.misc.STMessage;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/** */
|
||||
public abstract class Target {
|
||||
/** For pure strings of Java 16-bit Unicode char, how can we display
|
||||
|
@ -504,9 +506,10 @@ public abstract class Target {
|
|||
|
||||
public boolean templatesExist() {
|
||||
String groupFileName = CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION;
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(groupFileName);
|
||||
STGroup result = null;
|
||||
try {
|
||||
result = new STGroupFile(groupFileName);
|
||||
result = new STGroupFile(url.getPath());
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
result = null;
|
||||
|
@ -517,9 +520,11 @@ public abstract class Target {
|
|||
|
||||
protected STGroup loadTemplates() {
|
||||
String groupFileName = CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION;
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(groupFileName);
|
||||
|
||||
STGroup result = null;
|
||||
try {
|
||||
result = new STGroupFile(groupFileName);
|
||||
result = new STGroupFile(url.getPath());
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
gen.tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES,
|
||||
|
|
|
@ -231,8 +231,7 @@ public class ErrorManager {
|
|||
setFormat("antlr"); // recurse on this rule, trying the default message format
|
||||
return;
|
||||
}
|
||||
|
||||
format = new STGroupFile(fileName, "UTF-8");
|
||||
format = new STGroupFile(url, "UTF-8", '<', '>');
|
||||
format.load();
|
||||
|
||||
if ( !initSTListener.errors.isEmpty() ) {
|
||||
|
|
Loading…
Reference in New Issue