from browser import window __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 vto_structure = line[1].strip().split(">")[1].split("<")[0] vto_name = line[2].strip() vto_id = line[6].strip() if 0 in (len(vto_name), len(vto_id)): continue vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_structure, vto_id)) def convert_structure(structure, type): if structure_conversions is None: build_structure_conversions() for vfrom, vto_name, vto_structure, vto_id in structure_conversions: match = structure.match(vfrom) # fix for ids 106, 107, 44 which instead matched with 30 if match and vto_id == '30' and '-s' in type: vto_name = 's0-vp-s0' vto_id = '106' elif match and vto_id == '30' and '-g' in type: vto_name = 'gg-vp-gg' vto_id = '107' elif match and vto_id == '30' and '-r' in type: vto_name = 'r-vp-r' vto_id = '44' 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_name).strip() __pragma__('alias', 'replace', "py_replace") return result, vto_structure, vto_id window.console.log("Unknown structure: ", structure) return 'N/A', '/'