Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nojanath/SublimeKSP
Browse files Browse the repository at this point in the history
  • Loading branch information
eitherys committed Jun 8, 2019
2 parents 8132851 + ccbc80a commit f075dd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions ksp_compiler3/ksp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,21 @@ def split_args(arg_string, line):
args = []
cur_arg = ''
unmatched_left_paren = 0
for ch in arg_string + ',': # extra ',' to include the last argument
single_quote_on = False
double_quote_on = False

print(arg_string)
for idx, ch in enumerate(arg_string + ','): # extra ',' to include the last argument
# square brackets are also checked as there may be commas in them (for properties/2D arrays)
if ch == '(' or ch == '[':
if ch is '\'':
single_quote_on = not single_quote_on
elif ch is '\"' and (idx == 0 or arg_string[idx - 1] is not '\\'):
double_quote_on = not double_quote_on
elif ch in ['(', '[']:
unmatched_left_paren += 1
elif ch == ')' or ch == ']':
elif ch in [')', ']']:
unmatched_left_paren -= 1
if ch == ',' and unmatched_left_paren == 0:
if ch == ',' and unmatched_left_paren == 0 and not single_quote_on and not double_quote_on:
cur_arg = cur_arg.strip()
if not cur_arg:
raise ParseException(line, 'Syntax error - empty argument in function call: %s' % arg_string)
Expand Down
2 changes: 1 addition & 1 deletion ksp_compiler3/preprocessor_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def handleOpenSizeArrays(lines):
line = lines[lineIdx].command.strip()
m = re.search(openArrayRe, line)
if m:
stringList = re.split(commasNotInBrackets, line[line.find("(") + 1 : len(line) - 1])
stringList = ksp_compiler.split_args(line[line.find("(") + 1 : len(line) - 1], line)
numElements = len(stringList)
name = m.group("name")
newLines.append(lines[lineIdx].copy(line[: line.find("[") + 1] + str(numElements) + line[line.find("[") + 1 :]))
Expand Down

0 comments on commit f075dd6

Please sign in to comment.