Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions stringstripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
COMMENT = ["//", "--"]
COMMENT_START = ["/*", "--[["]
COMMENT_END = ["*/", "]]"]
TABLE_INDEX_BRACKET_START = ["["]
TABLE_INDEX_BRACKET_END = ["]"]

ALL_SYMBOLS = STRING_START_MULTILINE + STRING_END_MULTILINE + \
STRING_START + STRING_END + COMMENT + COMMENT_START + COMMENT_END
Expand All @@ -23,6 +25,8 @@ def strip(lua):
# Strip comments
lua, removed_comments = strip_comments(lua)

lua = _replace_bracket_table_index(lua)

# Check for failure
for s in ALL_SYMBOLS:
if s in lua:
Expand Down Expand Up @@ -132,6 +136,23 @@ def _strip_multiline_strings(lua):
return lua, removed


def _replace_bracket_table_index(lua):
for i in range(len(TABLE_INDEX_BRACKET_START)):
start, end = TABLE_INDEX_BRACKET_START[i], TABLE_INDEX_BRACKET_END[i]
r = _build_regex(start, end)

_offset = 0
while True:
match = r.search(lua, _offset)
if match is None:
break

pre = lua[:match.start()] + " " + match.group() + " "
lua = pre + lua[match.end():]
_offset = len(pre) # we need to do this because we dont remove those brackets which would result in an infinite loop
return lua


string_index = -1
def _build_string_placeholder():
global string_index
Expand Down