diff --git a/compilerAst/src/prog8/parser/Prog8Parser.kt b/compilerAst/src/prog8/parser/Prog8Parser.kt index 35901b82e..0cde17230 100644 --- a/compilerAst/src/prog8/parser/Prog8Parser.kt +++ b/compilerAst/src/prog8/parser/Prog8Parser.kt @@ -41,19 +41,12 @@ object Prog8Parser { parseTree.block().forEach { module.add(it.toAst(module.isLibrary(), PetsciiEncoding)) } return module - } - - // FIXME: hacking together a path string: - private fun SourceCode.pathString() = - origin - .substringAfter("") + } private class ParsedModule(src: SourceCode) : Module( // FIXME: hacking together a name for the module: name = src.pathString() - .substringBeforeLast(".") + .substringBeforeLast(".") // must also work with an origin = "" .substringAfterLast("/") .substringAfterLast("\\") .replace("String@", "anonymous_"), diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index c8744d628..005d90fbf 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -10,16 +10,32 @@ import kotlin.io.path.* * Encapsulates - and ties together - actual source code (=text) * and its [origin]. */ -abstract class SourceCode() { +abstract class SourceCode { + + /** + * To be used *only* by the parser (as input to a TokenStream). + * DO NOT mess around with! + */ + internal abstract fun getCharStream(): CharStream + /** * 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 [fromPath]) * * `` if was created via [of] - * * `` if it came from resources (see [fromResources]) + * * `@embedded@/x/y/z.ext` if it came from resources (see [fromResources]) */ abstract val origin: String - abstract fun getCharStream(): CharStream + + + /** + * FIXME: hacking together a [SourceCode]'s "path string" + * 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*) + */ + fun pathString() = + origin + .substringAfter("<").substringBeforeLast(">") // or from plain string? /** * The source code as plain string. @@ -92,7 +108,7 @@ abstract class SourceCode() { reason = "looked in resources rooted at $rscRoot") } return object : SourceCode() { - override val origin = "" + override val origin = "@embedded@$normalized" override fun getCharStream(): CharStream { val inpStr = object{}.javaClass.getResourceAsStream(normalized) val chars = CharStreams.fromStream(inpStr)