diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index a5ae77086..6e9e1129f 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -17,11 +17,16 @@ private data class NumericLiteral(val number: Number, val datatype: DataType) private fun ParserRuleContext.toPosition() : Position { - val path = Path.of(start.inputStream.sourceName) - val filename = if(path.isRegularFile()) { - SourceCode.relative(Path.of(start.inputStream.sourceName)).toString() + val pathString = start.inputStream.sourceName + val filename = if(SourceCode.isRegularFilesystemPath(pathString)) { + val path = Path.of(pathString) + if(path.isRegularFile()) { + SourceCode.relative(path).toString() + } else { + path.toString().substringAfter("<").substringBeforeLast(">") // TODO fix the need to get rid of the < and > + } } else { - path.toString().substringAfter("<").substringBeforeLast(">") + pathString.substringAfter("<").substringBeforeLast(">") // TODO fix the need to get rid of the < and > } // note: beware of TAB characters in the source text, they count as 1 column... return Position(filename, start.line, start.charPositionInLine, stop.charPositionInLine + stop.text.length) diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index 9ab2adfef..380eb3384 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -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]) - * * `` if was created via [String] + * * `$stringSourcePrefix44c56085>` 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 @@ -43,6 +43,7 @@ sealed class SourceCode { /** * This is really just [origin] with any stuff removed that would render it an invalid path name. * (Note: a *valid* path name does NOT mean that the denoted file or folder *exists*) + * TODO this promise doesn't work.... a "library:/...." resource path is not valid on Windows for example */ fun pathString() = origin.substringAfter("<").substringBeforeLast(">") // or from plain string? @@ -64,17 +65,20 @@ 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 = "`. + * [origin] will be something like `$stringSourcePrefix44c56085>`. */ class Text(val text: String): SourceCode() { override val isFromResources = false - override val origin = "" + override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>" override fun getCharStream(): CharStream = CharStreams.fromString(text, origin) }