fix problematic characters that cause path errors on Windows

This commit is contained in:
Irmen de Jong 2022-06-05 11:46:37 +02:00
parent 9e3e2ff81a
commit af2ca7a67e
4 changed files with 9 additions and 9 deletions

View File

@ -11,6 +11,6 @@ data class Position(val file: String, val line: Int, val startCol: Int, val endC
}
companion object {
val DUMMY = Position("<dummy>", 0, 0, 0)
val DUMMY = Position("~dummy~", 0, 0, 0)
}
}

View File

@ -34,7 +34,7 @@ sealed class SourceCode {
* Where this [SourceCode] instance came from.
* This can be one of the following:
* * a normal string representation of a [java.nio.file.Path], if it originates from a file (see [File])
* * `$stringSourcePrefix44c56085>` if was created via [String]
* * `string:44c56085` if was created via [String]
* * `library:/x/y/z.ext` if it is a library file that was loaded from resources (see [Resource])
*/
abstract val origin: String
@ -55,7 +55,7 @@ sealed class SourceCode {
* filename prefix to designate library files that will be retreived from internal resources rather than disk
*/
const val libraryFilePrefix = "library:"
const val stringSourcePrefix = "<String@"
const val stringSourcePrefix = "string:"
val curdir: Path = Path(".").toAbsolutePath()
fun relative(path: Path): Path = curdir.relativize(path.toAbsolutePath())
fun isRegularFilesystemPath(pathString: String) =
@ -64,12 +64,12 @@ sealed class SourceCode {
/**
* Turn a plain String into a [SourceCode] object.
* [origin] will be something like `$stringSourcePrefix44c56085>`.
* [origin] will be something like `string:44c56085`.
*/
class Text(override val text: String): SourceCode() {
override val isFromResources = false
override val isFromFilesystem = false
override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>"
override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}"
override val name = "<unnamed-text>"
}

View File

@ -204,7 +204,7 @@ class TestProg8Parser: FunSpec( {
val module = parseModule(SourceCode.Text(srcText))
// Note: assertContains has *actual* as first param
module.name shouldContain Regex("^<String@[0-9a-f\\-]+>$")
module.name shouldContain Regex("^string:[0-9a-f\\-]+$")
}
test("parsed from a file") {
@ -267,7 +267,7 @@ class TestProg8Parser: FunSpec( {
val srcText = "bad * { }\n"
val e = shouldThrow<ParseError> { parseModule(SourceCode.Text(srcText)) }
assertPosition(e.position, Regex("^<String@[0-9a-f\\-]+>$"), 1, 4, 4)
assertPosition(e.position, Regex("^string:[0-9a-f\\-]+$"), 1, 4, 4)
}
test("in ParseError from bad file source code") {
@ -283,7 +283,7 @@ class TestProg8Parser: FunSpec( {
}
"""
val module = parseModule(SourceCode.Text(srcText))
assertPositionOf(module, Regex("^<String@[0-9a-f\\-]+>$"), 1, 0)
assertPositionOf(module, Regex("^string:[0-9a-f\\-]+$"), 1, 0)
}
test("of Module parsed from a file") {

View File

@ -19,7 +19,7 @@ class TestSourceCode: AnnotationSpec() {
"""
val src = SourceCode.Text(text)
src.origin shouldContain Regex("^<String@[0-9a-f\\-]+>$")
src.origin shouldContain Regex("^string:[0-9a-f\\-]+$")
src.text shouldBe text
src.isFromResources shouldBe false
src.isFromFilesystem shouldBe false