forked from jasder/antlr
Support specifying the inputDirectory in code
This commit is contained in:
parent
35aeeb7c5c
commit
95f5cc6b8b
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue