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

fix is-grammar-file-check

- resolves #7
parent 147c7088
No related branches found
No related tags found
No related merge requests found
......@@ -25,9 +25,20 @@ public abstract class RelAstProcessor extends AbstractCompiler {
super(name, jastAddCompliant);
}
protected boolean isGrammarFile(String fileName) {
String extension = fileName.subSequence(fileName.lastIndexOf('.'), fileName.length()).toString();
return extension.equals(".relast") || extension.equals(".ast");
protected boolean isGrammarFile(Path path) {
if (path.getFileName() == null) { return false; }
String fileName = path.getFileName().toString();
int dotIndex = fileName.lastIndexOf('.');
if (dotIndex < 0) {
printMessage(path + " has no extension, ignoring it.");
return false;
}
String extension = fileName.subSequence(dotIndex, fileName.length()).toString();
boolean isGrammar = extension.equals(".relast") || extension.equals(".ast");
if (!isGrammar) {
printMessage(path + " is not a grammar file, ignoring it.");
}
return isGrammar;
}
@Override
......@@ -112,7 +123,7 @@ public abstract class RelAstProcessor extends AbstractCompiler {
RelAstParser parser = new RelAstParser();
inputFiles.stream().filter(path -> isGrammarFile(path.toString())).forEach(
inputFiles.stream().filter(this::isGrammarFile).forEach(
path -> {
try (BufferedReader reader = Files.newBufferedReader(path)) {
RelAstScanner scanner = new RelAstScanner(reader);
......
......@@ -22,12 +22,6 @@ public class RelastSourceToSourceCompiler extends RelAstProcessor {
}
}
@Override
protected boolean isGrammarFile(String fileName) {
String extension = fileName.subSequence(fileName.lastIndexOf("."), fileName.length()).toString();
return extension.equals(".relast") || extension.equals(".ast");
}
@Override
protected int processGrammar(Program program, Path inputBasePath, Path outputBasePath) throws CompilerException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment