diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 110e56a0e..666268e25 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -14,15 +14,6 @@ private data class NumericLiteral(val number: Number, val datatype: DataType) private fun ParserRuleContext.toPosition() : Position { - /* - val customTokensource = this.start.tokenSource as? CustomLexer - val filename = - when { - customTokensource!=null -> customTokensource.modulePath.toString() - start.tokenSource.sourceName == IntStream.UNKNOWN_SOURCE_NAME -> "@internal@" - else -> File(start.inputStream.sourceName).name - } - */ val filename = start.inputStream.sourceName // note: beware of TAB characters in the source text, they count as 1 column... diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index df1975aef..a27e5ed11 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -4,6 +4,9 @@ import org.antlr.v4.runtime.CharStream import org.antlr.v4.runtime.CharStreams import java.io.File import java.io.IOException +import java.nio.channels.Channels +import java.nio.charset.CodingErrorAction +import java.nio.charset.StandardCharsets import java.nio.file.Path import kotlin.io.path.absolutePathString import kotlin.io.path.exists @@ -72,7 +75,7 @@ sealed class SourceCode { class Text(val text: String): SourceCode() { override val isFromResources = false override val origin = "" - override fun getCharStream(): CharStream = CharStreams.fromString(text) + override fun getCharStream(): CharStream = CharStreams.fromString(text, origin) } /** @@ -124,8 +127,10 @@ sealed class SourceCode { override val isFromResources = true override val origin = "$libraryFilePrefix$normalized" override fun getCharStream(): CharStream { - val inpStr = object {}.javaClass.getResourceAsStream(normalized) - return CharStreams.fromStream(inpStr) + val inpStr = object {}.javaClass.getResourceAsStream(normalized)!! + // CharStreams.fromStream() doesn't allow us to set the stream name properly, so we use a lower level api + val channel = Channels.newChannel(inpStr) + return CharStreams.fromChannel(channel, StandardCharsets.UTF_8, 4096, CodingErrorAction.REPLACE, origin, -1); } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 799c2b183..5b21b6837 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,9 +3,7 @@ TODO For next compiler release ^^^^^^^^^^^^^^^^^^^^^^^^^ -- fix "unknown" reported in resulting .asm as source file of included library modules/resources - unittest: "of non-root Nodes parsed from a string" - +- fix weird error when doing %import textio.p8 Blocked by Commander-x16 v39 release diff --git a/examples/test.p8 b/examples/test.p8 index e52d7a5c9..b145e07ec 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,7 +4,7 @@ main { str myBar = "main.bar" foo_bar: - %asminclude "compiler/test/fixtures/foo_bar.asm22" ; FIXME: should be accessible from inside start() but give assembler error + ; %asminclude "compiler/test/fixtures/foo_bar.asm22" ; FIXME: should be accessible from inside start() but give assembler error sub start() { txt.print(myBar)