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