From 7810e46e00799fab24e35d59ca1966d8c957a418 Mon Sep 17 00:00:00 2001 From: Nabeel Ansari Date: Tue, 9 Jun 2020 15:30:13 -0400 Subject: [PATCH] Define macro now ignores usage inside string quotes correctly. --- ksp_compiler3/preprocessor_plugins.py | 6 ++++++ messages.json | 3 ++- messages/1.9.9.txt | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 messages/1.9.9.txt diff --git a/ksp_compiler3/preprocessor_plugins.py b/ksp_compiler3/preprocessor_plugins.py index 2db562c..e271b32 100755 --- a/ksp_compiler3/preprocessor_plugins.py +++ b/ksp_compiler3/preprocessor_plugins.py @@ -1156,6 +1156,11 @@ def substituteValue(self, command, listOfOtherDefines, line=None): newCommand = re.sub(r"\b%s\b" % self.name, self.value, command) else: lineObj = line or self.line + + strings = re.findall(ksp_compiler.string_re, command) + for s in strings: + command = command.replace(s, ' ' * len(s)) + matchIt = re.finditer(r"\b%s\b" % self.name, command) for match in matchIt: # Parse the match @@ -1163,6 +1168,7 @@ def substituteValue(self, command, listOfOtherDefines, line=None): parenthCount = 0 preBracketFlag = True # Flag to show when the first bracket is found. foundString = [] + for char in command[matchPos:]: if char == "(": parenthCount += 1 diff --git a/messages.json b/messages.json index d7e48e4..deff9e6 100755 --- a/messages.json +++ b/messages.json @@ -35,5 +35,6 @@ "1.9.4": "messages/1.9.4.txt", "1.9.6": "messages/1.9.6.txt", "1.9.7": "messages/1.9.7.txt", - "1.9.8": "messages/1.9.8.txt" + "1.9.8": "messages/1.9.8.txt", + "1.9.9": "messages/1.9.9.txt" } diff --git a/messages/1.9.9.txt b/messages/1.9.9.txt new file mode 100644 index 0000000..6cc1103 --- /dev/null +++ b/messages/1.9.9.txt @@ -0,0 +1,14 @@ +Version 1.9.9 + +Fixed a bug where using any define macro names inside of strings would attempt to evaluate them instead of leaving them as string content. + +For example: + +``` +define real(x) := int_to_real(x) +on init +message("Ready for real-time audio!") +end on +``` + +This code would attempt to evaluate real as a function and cause the compiler to error due to lack of arguments. \ No newline at end of file