possible fix for windows
This commit is contained in:
parent
048cbac0b4
commit
3dade998ba
@ -14,26 +14,36 @@
|
||||
|
||||
package triangle.syntacticAnalyzer;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class SourceFile {
|
||||
|
||||
public static final char EOL = '\n';
|
||||
public static final char EOT = '\u0000';
|
||||
|
||||
java.io.File sourceFile;
|
||||
java.io.FileInputStream source;
|
||||
java.io.InputStream source;
|
||||
int currentLine;
|
||||
|
||||
public static SourceFile ofPath(String pathname) {
|
||||
try {
|
||||
return new SourceFile(pathname);
|
||||
SourceFile sf = new SourceFile();
|
||||
sf.sourceFile = new java.io.File(pathname);
|
||||
sf.source = new java.io.FileInputStream(sf.sourceFile);
|
||||
return sf;
|
||||
} catch (java.io.IOException s) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static SourceFile fromResource(String handle) {
|
||||
SourceFile sf = new SourceFile();
|
||||
//sf.sourceFile = new java.io.File(pathname);
|
||||
sf.source = sf.getClass().getResourceAsStream(handle);
|
||||
return sf;
|
||||
}
|
||||
|
||||
private SourceFile(String pathname) throws java.io.FileNotFoundException {
|
||||
sourceFile = new java.io.File(pathname);
|
||||
source = new java.io.FileInputStream(sourceFile);
|
||||
private SourceFile() {
|
||||
currentLine = 1;
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,9 @@ public class TestScanner {
|
||||
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
||||
// which adds the programs directory to the list of places Java can easily find files
|
||||
// getResource() below searches for a file, which is in /programs
|
||||
SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString());
|
||||
|
||||
//SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString());
|
||||
SourceFile source = SourceFile.fromResource(filename);
|
||||
|
||||
Scanner scanner = new Scanner(source);
|
||||
ErrorReporter reporter = new ErrorReporter(true);
|
||||
Parser parser = new Parser(scanner, reporter);
|
||||
@ -63,7 +64,8 @@ public class TestScanner {
|
||||
}
|
||||
|
||||
private void compileExpectFailure(String filename) {
|
||||
SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString());
|
||||
//SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString());
|
||||
SourceFile source = SourceFile.fromResource(filename);
|
||||
Scanner scanner = new Scanner(source);
|
||||
ErrorReporter reporter = new ErrorReporter(true);
|
||||
Parser parser = new Parser(scanner, reporter);
|
||||
|
Reference in New Issue
Block a user