__pragma__ ('noanno') __pragma__ ('js', """ var fs = require('fs'); var conversion_csv = fs.readFileSync('build/conversions.csv', 'utf8'); """, None) # above is magically read (browserify plugin) at compile time # browserify is run from root, so we need build/ in path for this to work # convert to useful structure structure_conversions = None def build_structure_conversions(): global structure_conversions structure_conversions = [] structure_conversions_raw = [line.split(",") for line in conversion_csv.split("\n")] for line in structure_conversions_raw: if min(len(line[0]), len(line[1])) == 0: continue # header if line[1] == "struktura": continue vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" vto = line[1].replace("", "").replace("", "").replace("%s", "$1").strip() structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto)) def convert_structure(structure): if structure_conversions is None: build_structure_conversions() for vfrom, vto in structure_conversions: match = structure.match(vfrom) if match: # we need to remove replace alias here as we want to use javascript's one __pragma__('noalias', 'replace') result = structure.replace(vfrom, vto).strip() __pragma__('alias', 'replace', "py_replace") # they said this also needs to be done - remove "-d$" from %s match if len(match) > 1 and match[1].endswith("-d"): result = result.replace(match[1], match[1][:-2]) return result return None