Support specifying the inputDirectory in code

This commit is contained in:
Sam Harwell 2012-04-10 09:49:31 -05:00
parent 35aeeb7c5c
commit 95f5cc6b8b
1 changed files with 8 additions and 2 deletions

View File

@ -106,6 +106,7 @@ public class Tool {
// fields set by option manager
public File inputDirectory;
public String outputDirectory;
public String libDirectory;
public boolean report = false;
@ -381,7 +382,12 @@ public class Tool {
public GrammarRootAST loadGrammar(String fileName) {
try {
ANTLRFileStream in = new ANTLRFileStream(fileName, grammarEncoding);
File file = new File(fileName);
if (!file.isAbsolute()) {
file = new File(inputDirectory, fileName);
}
ANTLRFileStream in = new ANTLRFileStream(file.getAbsolutePath(), grammarEncoding);
GrammarRootAST t = load(in);
return t;
}
@ -510,7 +516,7 @@ public class Tool {
}
public File getImportedGrammarFile(Grammar g, String fileName) {
File importedFile = new File(fileName);
File importedFile = new File(inputDirectory, fileName);
if ( !importedFile.exists() ) {
File gfile = new File(g.fileName);
String parentDir = gfile.getParent();