Skip to content

Commit

Permalink
Define macro now ignores usage inside string quotes correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
eitherys committed Jun 9, 2020
1 parent 119b1eb commit 7810e46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ksp_compiler3/preprocessor_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,13 +1156,19 @@ 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
matchPos = match.start()
parenthCount = 0
preBracketFlag = True # Flag to show when the first bracket is found.
foundString = []

for char in command[matchPos:]:
if char == "(":
parenthCount += 1
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
14 changes: 14 additions & 0 deletions messages/1.9.9.txt
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 7810e46

Please sign in to comment.