From be29040b96a8dbee436722bb23c3aabc7bf5cf4f Mon Sep 17 00:00:00 2001 From: xxalpha Date: Thu, 25 Feb 2016 22:48:54 +0000 Subject: [PATCH] parser will now ignore preceding whitespace in var blocks; removed unused file penis --- tools/mapmerge/dmm2tgm.py | 70 ----------------------------------- tools/mapmerge/map_helpers.py | 14 +++++-- tools/mapmerge/mapmerger.py | 1 - 3 files changed, 11 insertions(+), 74 deletions(-) delete mode 100644 tools/mapmerge/dmm2tgm.py diff --git a/tools/mapmerge/dmm2tgm.py b/tools/mapmerge/dmm2tgm.py deleted file mode 100644 index 9c25eee2189e0..0000000000000 --- a/tools/mapmerge/dmm2tgm.py +++ /dev/null @@ -1,70 +0,0 @@ - -import sys - -# .dmm format converter, by RemieRichards -# Version 2.0 -# Converts the internal structure of a .dmm file to a syntax -# that git can better handle conflicts-wise, it's also fairly human readable! -# Processes Boxstation (tgstation.2.1.3) almost instantly - - -def convert_map(map_file): - #CHECK FOR PREVIOUS CONVERSION - with open(map_file, "r") as conversion_candidate: - header = conversion_candidate.readline() - if header.find("//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE") != -1: - sys.exit() - return - - - #ACTUAL CONVERSION - with open(map_file, "r+") as unconverted_map: - characters = unconverted_map.read() - converted_map = "" - in_object_block = False #() - in_variable_block = False #{} - in_quote_block = False #'' - in_double_quote_block = False #"" - for char in characters: - if not in_quote_block: #Checking for things like "Flashbangs (Warning!)" Because we only care about ({'";, that are used as byond syntax, not strings - if not in_double_quote_block: - if not in_variable_block: - if char == "(": - in_object_block = True - char = char + "\n" - if char == ")": - in_object_block = False - if char == ",": - char = char + "\n" - - if char == "{": - in_variable_block = True - if in_object_block: - char = char + "\n\t" - if char == "}": - in_variable_block = False - if in_object_block: - char = "\n\t" + char - - if char == ";": - char = char + "\n\t" - - if char == "\"": - if in_double_quote_block: - in_double_quote_block = False - else: - in_double_quote_block = True - - if char == "'": - if not in_double_quote_block: - if in_quote_block: - in_quote_block = False - else: - in_quote_block = True - - converted_map = converted_map + char - - #OVERWRITE MAP FILE WITH CONVERTED MAP STRING - with open(map_file, "r+") as final_converted_map: - final_converted_map.write("//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE \n") - final_converted_map.write(converted_map) diff --git a/tools/mapmerge/map_helpers.py b/tools/mapmerge/map_helpers.py index e57a86a6f2b8b..522d48b82e65c 100644 --- a/tools/mapmerge/map_helpers.py +++ b/tools/mapmerge/map_helpers.py @@ -136,7 +136,6 @@ def write_dictionary_tgm(filename, dictionary): for thing in list_: buffer = "" in_quote_block = False - escaping_quote = False in_varedit_block = False for char in thing: @@ -226,13 +225,12 @@ def parse_map(map_file): characters = map_input.read() in_quote_block = False - escaping_quote = False in_key_block = False in_data_block = False in_varedit_block = False after_data_block = False - escaping_parenthesis = 0 escaping = False + skip_whitespace = False dictionary = collections.OrderedDict() curr_key = "" @@ -285,12 +283,22 @@ def parse_map(map_file): curr_datum = curr_datum + char continue + + if skip_whitespace and char == " ": + skip_whitespace = False + continue + skip_whitespace = False if char == "\"": curr_datum = curr_datum + char in_quote_block = True continue + if char == ";": + skip_whitespace = True + curr_datum = curr_datum + char + continue + if char == "}": curr_datum = curr_datum + char in_varedit_block = False diff --git a/tools/mapmerge/mapmerger.py b/tools/mapmerge/mapmerger.py index 8691d872aedcd..d4ddf5e3a53cc 100644 --- a/tools/mapmerge/mapmerger.py +++ b/tools/mapmerge/mapmerger.py @@ -1,7 +1,6 @@ import sys import os import pathlib -import dmm2tgm import map_helpers #main("../../_maps/")