diff --git a/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala b/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala index c2b1aec0..8553d4d5 100644 --- a/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala +++ b/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala @@ -60,13 +60,13 @@ abstract class AbstractSourceLoadingQueue[T](val initialFilenames: List[String], options.log.debug(s"Parsing $filename") val path = Paths.get(filename) val parentDir = path.toFile.getAbsoluteFile.getParent - val PreprocessingResult(src, featureConstants, pragmas) = Preprocessor(options, Files.readAllLines(path, StandardCharsets.UTF_8).toIndexedSeq) + val shortFileName = path.getFileName.toString + val PreprocessingResult(src, featureConstants, pragmas) = Preprocessor(options, shortFileName, Files.readAllLines(path, StandardCharsets.UTF_8).toIndexedSeq) for (pragma <- pragmas) { if (!supportedPragmas(pragma._1)) { options.log.warn(s"Unsupported pragma: #pragma $pragma", Some(Position(moduleName, pragma._2, 1, 0))) } } - val shortFileName = path.getFileName.toString val parser = createParser(shortFileName, src, parentDir, featureConstants, pragmas.keySet) options.log.addSource(shortFileName, src.lines.toIndexedSeq) parser.toAst match { diff --git a/src/main/scala/millfork/parser/Preprocessor.scala b/src/main/scala/millfork/parser/Preprocessor.scala index a4e8f909..467b6f4d 100644 --- a/src/main/scala/millfork/parser/Preprocessor.scala +++ b/src/main/scala/millfork/parser/Preprocessor.scala @@ -18,12 +18,12 @@ object Preprocessor { private val Regex = raw"\A\s*#\s*([a-z]+)\s*(.*?)\s*\z".r def preprocessForTest(options: CompilationOptions, code: String): PreprocessingResult = { - apply(options, code.lines.toSeq) + apply(options, "", code.lines.toSeq) } case class IfContext(hadEnabled: Boolean, hadElse: Boolean, enabledBefore: Boolean) - def apply(options: CompilationOptions, lines: Seq[String]): PreprocessingResult = { + def apply(options: CompilationOptions, shortFileName: String, lines: Seq[String]): PreprocessingResult = { val platform = options.platform val log = options.log // if (log.traceEnabled) { @@ -55,7 +55,7 @@ object Preprocessor { var resulting = "" line match { case Regex(keyword, param) => - val pos = Some(Position("", lineNo, 0, 0)) + val pos = Some(Position(shortFileName, lineNo, 0, 0)) keyword match { case "use" => if (enabled) { if (param == "") log.error("#use should have a parameter", pos)