From d906d8aab4ffcffe965d2f382fc37db088f3cb4f Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 4 Nov 2019 02:29:44 +0100 Subject: [PATCH] Allow comments after `#endif` and `#else` --- src/main/scala/millfork/parser/Preprocessor.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/scala/millfork/parser/Preprocessor.scala b/src/main/scala/millfork/parser/Preprocessor.scala index 54eb2654..df55ffc9 100644 --- a/src/main/scala/millfork/parser/Preprocessor.scala +++ b/src/main/scala/millfork/parser/Preprocessor.scala @@ -23,6 +23,11 @@ object Preprocessor { case class IfContext(hadEnabled: Boolean, hadElse: Boolean, enabledBefore: Boolean) + private def isNotEmpty(s: String): Boolean = { + val isEmpty = s.isEmpty || s.startsWith("//") || s.forall(_ == ';') + ! isEmpty + } + def apply(options: CompilationOptions, shortFileName: String, lines: Seq[String]): PreprocessingResult = { val platform = options.platform val log = options.log @@ -104,7 +109,7 @@ object Preprocessor { ifStack.push(IfContext(hadEnabled = false, hadElse = false, enabledBefore = false)) } case "endif" => - if (param != "") log.error("#endif shouldn't have a parameter", pos) + if (isNotEmpty(param)) log.error("#endif shouldn't have a parameter", pos) if (ifStack.isEmpty) log.error("Unmatched #endif", pos) else { enabled = ifStack.pop().enabledBefore @@ -124,7 +129,7 @@ object Preprocessor { } } case "else" => - if (param != "") { + if (isNotEmpty(param)) { log.error("#else shouldn't have a parameter", pos) if (param.startsWith("if ")) { log.error("Did you mean: #elseif")