1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-10 20:29:35 +00:00

Source file name in preprocessor errors

This commit is contained in:
Karol Stasiak 2018-12-24 01:20:41 +01:00
parent acaaa5bdfe
commit aebae97cc8
2 changed files with 5 additions and 5 deletions

View File

@ -60,13 +60,13 @@ abstract class AbstractSourceLoadingQueue[T](val initialFilenames: List[String],
options.log.debug(s"Parsing $filename") options.log.debug(s"Parsing $filename")
val path = Paths.get(filename) val path = Paths.get(filename)
val parentDir = path.toFile.getAbsoluteFile.getParent 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) { for (pragma <- pragmas) {
if (!supportedPragmas(pragma._1)) { if (!supportedPragmas(pragma._1)) {
options.log.warn(s"Unsupported pragma: #pragma $pragma", Some(Position(moduleName, pragma._2, 1, 0))) 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) val parser = createParser(shortFileName, src, parentDir, featureConstants, pragmas.keySet)
options.log.addSource(shortFileName, src.lines.toIndexedSeq) options.log.addSource(shortFileName, src.lines.toIndexedSeq)
parser.toAst match { parser.toAst match {

View File

@ -18,12 +18,12 @@ object Preprocessor {
private val Regex = raw"\A\s*#\s*([a-z]+)\s*(.*?)\s*\z".r private val Regex = raw"\A\s*#\s*([a-z]+)\s*(.*?)\s*\z".r
def preprocessForTest(options: CompilationOptions, code: String): PreprocessingResult = { 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) 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 platform = options.platform
val log = options.log val log = options.log
// if (log.traceEnabled) { // if (log.traceEnabled) {
@ -55,7 +55,7 @@ object Preprocessor {
var resulting = "" var resulting = ""
line match { line match {
case Regex(keyword, param) => case Regex(keyword, param) =>
val pos = Some(Position("", lineNo, 0, 0)) val pos = Some(Position(shortFileName, lineNo, 0, 0))
keyword match { keyword match {
case "use" => if (enabled) { case "use" => if (enabled) {
if (param == "") log.error("#use should have a parameter", pos) if (param == "") log.error("#use should have a parameter", pos)