Skip to content

Commit

Permalink
Add a .SIZE define for literal defines
Browse files Browse the repository at this point in the history
These contain the amount of entries in a literal define.
Example:

define FOO := apple, banana, pear, kiwi

Adds a FOO.SIZE define that has a value of 4.

Closes nojanath#99
  • Loading branch information
mkruselj committed Dec 2, 2023
1 parent db563d4 commit 5026061
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/preprocessor_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,14 @@ def handleDefineConstants(lines, define_cache = None):
newLines.append(l)
continue

# count number of string replacement token openers to figure out if we're defining literals
num_literals = m.group("val").count("{")

if num_literals > 0:
# add define for amount of entries in a literal define (.SIZE suffix)
defineSizeObj = DefineConstant(m.group("whole") + '.SIZE', str(num_literals), None, l)
defineConstants.append(defineSizeObj)

# Create define and evaluate if legitimate
defineObj = DefineConstant(m.group("whole"), m.group("val").strip(), m.group("args"), l)

Expand Down

0 comments on commit 5026061

Please sign in to comment.