Skip to content
Snippets Groups Projects
Commit 2850be7f authored by René Schöne's avatar René Schöne
Browse files

import command line messages

- fix handling of absolute input files
- see #5
parent 86d0d611
Branches
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ public class Mustache {
Template template = handlebars.compile(templateFileName);
try (Writer w = new FileWriter(outputFileName)) {
System.out.println("Writing " + outputFileName);
template.apply(context, w);
w.flush();
}
......
......@@ -55,14 +55,14 @@ public abstract class RelAstProcessor extends AbstractCompiler {
inputBasePath = Paths.get(optionInputBaseDir.value()).toAbsolutePath();
} else {
inputBasePath = Paths.get(".").toAbsolutePath();
printMessage("No input base dir is set. Assuming current directory '" + inputBasePath.toAbsolutePath().toString() + "'.");
printMessage("No input base dir is set. Assuming current directory '" + inputBasePath.toAbsolutePath() + "'.");
}
if (!inputBasePath.toFile().exists()) {
printMessage("Input path '" + inputBasePath.toAbsolutePath().toString() + "' does not exist. Exiting...");
printMessage("Input path '" + inputBasePath.toAbsolutePath() + "' does not exist. Exiting...");
System.exit(-1);
} else if (!inputBasePath.toFile().isDirectory()) {
printMessage("Input path '" + inputBasePath.toAbsolutePath().toString() + "' is not a directory. Exiting...");
printMessage("Input path '" + inputBasePath.toAbsolutePath() + "' is not a directory. Exiting...");
System.exit(-1);
}
......@@ -74,29 +74,29 @@ public abstract class RelAstProcessor extends AbstractCompiler {
}
if (outputBasePath.toFile().exists() && !outputBasePath.toFile().isDirectory()) {
printMessage("Output path '" + inputBasePath.toAbsolutePath().toString() + "' exists, but is not a directory. Exiting...");
printMessage("Output path '" + inputBasePath.toAbsolutePath() + "' exists, but is not a directory. Exiting...");
}
printMessage("Running " + getName());
// gather all files
Collection<Path> inputFiles = new ArrayList<>();
getConfiguration().getFiles().forEach(name -> relativizeFileName(inputBasePath, Paths.get(name)).ifPresent(inputFiles::add));
getConfiguration().getFiles().forEach(name -> checkFileName(inputBasePath, Paths.get(name)).ifPresent(inputFiles::add));
Program program = parseProgram(inputFiles);
Program program = parseProgram(inputBasePath, inputFiles);
return processGrammar(program, inputBasePath, outputBasePath);
}
protected abstract int processGrammar(Program program, Path inputBasePath, Path outputBasePath) throws CompilerException;
private Optional<Path> relativizeFileName(Path inputBasePath, Path filePath) {
private Optional<Path> checkFileName(Path inputBasePath, Path filePath) {
if (filePath.isAbsolute()) {
if (filePath.startsWith(inputBasePath)) {
return Optional.of(filePath.relativize(inputBasePath));
if (filePath.normalize().startsWith(inputBasePath.normalize())) {
return Optional.of(filePath);
} else {
printMessage("Path '" + filePath + "' is not contained in the base path '" + inputBasePath + "'.");
printMessage("Path '" + filePath + "' is not contained in the base path '" + inputBasePath + "', ignoring it.");
return Optional.empty();
}
} else {
......@@ -118,7 +118,7 @@ public abstract class RelAstProcessor extends AbstractCompiler {
}
}
private Program parseProgram(Collection<Path> inputFiles) {
private Program parseProgram(Path inputBasePath, Collection<Path> inputFiles) {
Program program = new Program();
RelAstParser parser = new RelAstParser();
......@@ -128,7 +128,7 @@ public abstract class RelAstProcessor extends AbstractCompiler {
try (BufferedReader reader = Files.newBufferedReader(path)) {
RelAstScanner scanner = new RelAstScanner(reader);
GrammarFile inputGrammar = (GrammarFile) parser.parse(scanner);
inputGrammar.setFileName(path.toString());
inputGrammar.setFileName(inputBasePath.relativize(path).toString());
program.addGrammarFile(inputGrammar);
} catch (IOException | beaver.Parser.Exception e) {
printMessage("Could not parse grammar file " + path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment