Reapplied changes that got lost during merge.

This commit is contained in:
Mike Lischke 2017-10-22 12:27:49 +02:00
parent b8fd54780a
commit 593da3df5e
2 changed files with 20 additions and 24 deletions

View File

@ -761,18 +761,11 @@ public class Tool {
File outputDir;
String fileDirectory;
// Some files are given to us without a PATH but should should
// still be written to the output directory in the relative path of
// the output directory. The file directory is either the set of sub directories
// 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) {
// No path is included in the file name, so make the file
// directory the same as the parent grammar (which might sitll be just ""
// directory the same as the parent grammar (which might still be just ""
// but when it is not, we will write the file in the correct place.
fileDirectory = ".";
}
else {
fileDirectory = fileNameWithPath.substring(0, fileNameWithPath.lastIndexOf(File.separatorChar));
@ -781,21 +774,8 @@ public class Tool {
// -o /tmp /var/lib/t.g4 => /tmp/T.java
// -o subdir/output /usr/lib/t.g4 => subdir/output/T.java
// -o . /usr/lib/t.g4 => ./T.java
if (fileDirectory != null &&
(new File(fileDirectory).isAbsolute() ||
fileDirectory.startsWith("~"))) { // isAbsolute doesn't count this :(
// somebody set the dir, it takes precendence; write new file there
outputDir = new File(outputDirectory);
}
else {
// -o /tmp subdir/t.g4 => /tmp/subdir/t.g4
if (fileDirectory != null) {
outputDir = new File(outputDirectory, fileDirectory);
}
else {
outputDir = new File(outputDirectory);
}
}
// -o /tmp subdir/t.g4 => /tmp/t.g4
outputDir = new File(outputDirectory);
}
else {
// they didn't specify a -o dir so just write to location

View File

@ -146,6 +146,22 @@ public class TokenVocabParser {
// files are generated (in the base, not relative to the input
// location.)
f = new File(g.tool.outputDirectory, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION);
return f;
if ( f.exists() ) {
return f;
}
// Still not found? Use the grammar's subfolder then.
String fileDirectory;
if (g.fileName.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 still be just ""
// but when it is not, we will write the file in the correct place.
fileDirectory = ".";
}
else {
fileDirectory = g.fileName.substring(0, g.fileName.lastIndexOf(File.separatorChar));
}
return new File(fileDirectory, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION);
}
}