From ba16021426f63b12d8b88bb7f1f158763566265b Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 14 Jun 2019 15:33:17 +0200 Subject: [PATCH] Allow using $$ instead of # in preprocessor directives --- docs/lang/preprocessor.md | 3 +++ src/main/scala/millfork/parser/Preprocessor.scala | 2 +- src/test/scala/millfork/test/BasicSymonTest.scala | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index de9b7e06..ec4b95a8 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -16,6 +16,9 @@ Despite its similarity to the C preprocessor, it's much more restricted in its p * separate namespaces for the preprocessor and the language (you need to use `#use` to use a preprocessor constant in the code) +Preprocessor directives by default start with `#`. +To avoid conflicts with C preprocessor (for users wishing to use it), it is also possible to replace `#` with `$$`. + ### Defining feature values Feature values are defined in the `[define]` section of the platform definition file. diff --git a/src/main/scala/millfork/parser/Preprocessor.scala b/src/main/scala/millfork/parser/Preprocessor.scala index 26a920dc..3f866e7d 100644 --- a/src/main/scala/millfork/parser/Preprocessor.scala +++ b/src/main/scala/millfork/parser/Preprocessor.scala @@ -15,7 +15,7 @@ case class PreprocessingResult(source: String, featureConstants: Map[String, Lon object Preprocessor { - private val Regex = raw"\A\s*#\s*([a-z]+)\s*(.*?)\s*\z".r + private val Regex = """\A\s*(?:#|\$\$)\s*([a-z]+)\s*(.*?)\s*\z""".r def preprocessForTest(options: CompilationOptions, code: String): PreprocessingResult = { apply(options, "", code.lines.toSeq) diff --git a/src/test/scala/millfork/test/BasicSymonTest.scala b/src/test/scala/millfork/test/BasicSymonTest.scala index d9caafd1..6cd22281 100644 --- a/src/test/scala/millfork/test/BasicSymonTest.scala +++ b/src/test/scala/millfork/test/BasicSymonTest.scala @@ -196,7 +196,7 @@ class BasicSymonTest extends FunSuite with Matchers { | #use ARCH_I80 | | #use HORSE = ARCH_6502 - | #use COW = ARCH_I80 + | $$use COW = ARCH_I80 | | #if 1 | asm void main () {