wmllint-1.4: use enumerate() to iterate over lines

This commit is contained in:
Elvish_Hunter 2015-09-14 23:43:30 +02:00
parent ac31185083
commit 2877a6a489

View file

@ -629,21 +629,21 @@ def sanity_check(filename, lines):
# Also, build dictionaries of unit movement types and races
in_unit = False
in_attack_filter = False
for i in range(len(lines)):
if "[attack_filter]" in lines[i]:
for i, line in enumerate(lines):
if "[attack_filter]" in line:
in_attack_filter = True
continue
elif "[/attack_filter]" in lines[i]:
elif "[/attack_filter]" in line:
in_attack_filter = False
continue
elif "[unit]" in lines[i]:
elif "[unit]" in line:
traits = []
notes = []
has_special_notes = False
derived_unit = False
in_unit = i+1
continue
elif "[/unit]" in lines[i]:
elif "[/unit]" in line:
#print('"%s", %d: unit has traits %s and notes %s' %
# (filename, in_unit, traits, notes))
if unit_id and not derived_unit:
@ -675,7 +675,7 @@ def sanity_check(filename, lines):
has_special_notes = False
if in_unit and not in_attack_filter:
try:
(key, prefix, value, comment) = parse_attribute(lines[i])
(key, prefix, value, comment) = parse_attribute(line)
if key == "id" and not unit_id:
if value[0] == "_":
value = value[1:].strip()
@ -693,43 +693,43 @@ def sanity_check(filename, lines):
unit_races.append((unit_id, filename, i+1, value))
except TypeError:
pass
if "{SPECIAL_NOTES}" in lines[i]:
if "{SPECIAL_NOTES}" in line:
has_special_notes = True
if "[base_unit]" in lines[i]:
if "[base_unit]" in line:
derived_unit = True
for (p, q) in notepairs:
if p in lines[i]:
if p in line:
traits.append(p)
if q in lines[i]:
if q in line:
notes.append(q)
# Collect information on defined movement types
in_movetype = False
for i in range(len(lines)):
if "[movetype]" in lines[i]:
for i, line in enumerate(lines):
if "[movetype]" in line:
in_movetype = True
continue
elif "[/movetype]" in lines[i]:
elif "[/movetype]" in line:
in_movetype = False
continue
if in_movetype:
try:
(key, prefix, value, comment) = parse_attribute(lines[i])
(key, prefix, value, comment) = parse_attribute(line)
if key == 'name':
movetypes.append(value)
except TypeError:
pass
# Collect information on defined races
in_race = False
for i in range(len(lines)):
if "[race]" in lines[i]:
for i, line in enumerate(lines):
if "[race]" in line:
in_race = True
continue
elif "[/race]" in lines[i]:
elif "[/race]" in line:
in_race = False
continue
if in_race:
try:
(key, prefix, value, comment) = parse_attribute(lines[i])
(key, prefix, value, comment) = parse_attribute(line)
if key == 'id':
races.append(value)
except TypeError:
@ -745,33 +745,33 @@ def sanity_check(filename, lines):
in_generator = False
sidecount = 0
recruitment_pattern = []
for i in range(len(lines)):
if "[generator]" in lines[i]:
for i, line in enumerate(lines):
if "[generator]" in line:
in_generator = True
continue
elif "[/generator]" in lines[i]:
elif "[/generator]" in line:
in_generator = False
continue
elif "[side]" in lines[i]:
elif "[side]" in line:
in_side = True
sidecount += 1
continue
elif "[/side]" in lines[i]:
elif "[/side]" in line:
if recruit and recruitment_pattern:
sides.append((filename, recruit, recruitment_pattern))
in_side = False
recruit = []
recruitment_pattern = []
continue
elif in_side and ("[unit]" in lines[i] or "[ai]" in lines[i]):
elif in_side and ("[unit]" in line or "[ai]" in line):
in_subtag = True
continue
elif in_side and ("[/side]" in lines[i] or "[/ai]" in lines[i]):
elif in_side and ("[/side]" in line or "[/ai]" in line):
in_subtag = False
if not in_side or in_subtag or '=' not in lines[i]:
if not in_side or in_subtag or '=' not in line:
continue
try:
(key, prefix, value, comment) = parse_attribute(lines[i])
(key, prefix, value, comment) = parse_attribute(line)
if key == "recruit" and value:
recruit = (i+1, [elem.strip() for elem in value.split(",")])
elif key == "recruitment_pattern" and value:
@ -797,37 +797,37 @@ def sanity_check(filename, lines):
in_objective = False
in_trait = False
ignoreable = False
for i in range(len(lines)):
if "[scenario]" in lines[i]:
for i, line in enumerate(lines):
if "[scenario]" in line:
in_scenario = True
elif "[/scenario]" in lines[i]:
elif "[/scenario]" in line:
in_scenario = False
elif "[objective]" in lines[i]:
elif "[objective]" in line:
in_objective = True
elif "[/objective]" in lines[i]:
elif "[/objective]" in line:
in_objective = False
elif "[trait]" in lines[i]:
elif "[trait]" in line:
in_trait = True
elif "[/trait]" in lines[i]:
elif "[/trait]" in line:
in_trait = False
elif "[kill]" in lines[i] or "[object]" in lines[i] or "[move_unit_fake]" in lines[i] or "[scroll_to_unit]" in lines[i]:
elif "[kill]" in line or "[object]" in line or "[move_unit_fake]" in line or "[scroll_to_unit]" in line:
ignoreable = True
elif "[/kill]" in lines[i] or "[/object]" in lines[i] or "[/move_unit_fake]" in lines[i] or "[/scroll_to_unit]" in lines[i]:
elif "[/kill]" in line or "[/object]" in line or "[/move_unit_fake]" in line or "[/scroll_to_unit]" in line:
ignoreable = False
elif "[side]" in lines[i] or "[unit]" in lines[i] or "[recall]" in lines[i]:
elif "[side]" in line or "[unit]" in line or "[recall]" in line:
in_person = True
continue
elif "[/side]" in lines[i] or "[/unit]" in lines[i] or "[/recall]" in lines[i]:
elif "[/side]" in line or "[/unit]" in line or "[/recall]" in line:
in_person = False
if not in_scenario:
continue
m = re.search("# *wmllint: recognize +(.*)", lines[i])
m = re.search("# *wmllint: recognize +(.*)", line)
if m:
present.append(string_strip(m.group(1)).strip())
if '=' not in lines[i] or ignoreable:
if '=' not in line or ignoreable:
continue
try:
(key, prefix, value, comment) = parse_attribute(lines[i])
(key, prefix, value, comment) = parse_attribute(line)
if "wmllint: ignore" in comment:
continue
if len(value) == 0:
@ -839,7 +839,7 @@ def sanity_check(filename, lines):
if '{' in value:
print('"%s", line %d: macro reference in translatable string' %
(filename, i+1))
if future and re.search("[.,!?] ", lines[i]):
if future and re.search("[.,!?] ", line):
print('"%s", line %d: extraneous space in translatable string' %
(filename, i+1))
# Check correctness of translation marks and descriptions
@ -884,17 +884,17 @@ def sanity_check(filename, lines):
# This copes with some wacky UtBS units that are defined with
# variant-spawning macros. The prototype comment looks like this:
#wmllint: usage of "Desert Fighter" is fighter
for i in range(len(lines)):
m = re.match('# *wmllint: usage of "([^"]*)" is +(.*)', lines[i])
for i, line in enumerate(lines):
m = re.match('# *wmllint: usage of "([^"]*)" is +(.*)', line)
if m:
usage[m.group(1)] = m.group(2).strip()
# Check for textdomain strings; should be exactly one, on line 1
# We will also take the opportunity to check if the file is a top-level main
textdomains = []
for i in range(len(lines)):
if ("[campaign]" in lines[i] or "[binary_path]" in lines[i] or "[textdomain]" in lines[i]) and not filename.endswith("_main.cfg") and not filename in is_main:
for i, line in enumerate(lines):
if ("[campaign]" in line or "[binary_path]" in line or "[textdomain]" in line) and not filename.endswith("_main.cfg") and not filename in is_main:
is_main.append(filename)
if "#textdomain" in lines[i]:
if "#textdomain" in line:
textdomains.append(i+1)
if not textdomains:
print('"%s", line 1: no textdomain string' % filename)
@ -965,10 +965,10 @@ def hack_syntax(filename, lines):
global versions
modcount = 0
# Ensure that every attack has a translatable description.
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
elif "[attack]" in lines[i]:
elif "[attack]" in line:
j = i;
have_description = False
while '[/attack]' not in lines[j]:
@ -1000,10 +1000,10 @@ def hack_syntax(filename, lines):
# Ensure that every speaker=narrator block without an image uses
# wesnoth-icon.png as an image.
need_image = False
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
precomment = lines[i].split("#")[0]
precomment = line.split("#")[0]
if "speaker=narrator" in precomment:
need_image = True
elif precomment.strip().startswith("image"):
@ -1014,7 +1014,7 @@ def hack_syntax(filename, lines):
if verbose:
print('wmllint: "%s", line %d: inserting "image=wesnoth-icon.png"'%(filename, i+1))
lines.insert(i, leader(precomment) + baseindent + "image=wesnoth-icon.png\n")
modcount += 1
modcount += 1
need_image = False
# Remove get_hit_sound fields (and image_defensive, if also present)
in_unit = False
@ -1029,11 +1029,11 @@ def hack_syntax(filename, lines):
has_defense_anim = None
has_special_notes = False
image_done = []
for i in range(len(lines)):
if "[unit]" in lines[i]:
for i, line in enumerate(lines):
if "[unit]" in line:
in_unit = i+1
continue
elif "[/unit]" in lines[i]:
elif "[/unit]" in line:
if has_defense_anim:
if get_hit_sound:
print('wmllint: "%s", lines %d, %d: unit%s has both deprecated get_hit_sound key and a DEFENSE_ANIM' %
@ -1077,16 +1077,16 @@ def hack_syntax(filename, lines):
has_defense_anim = None
has_special_notes = False
if in_unit:
if "{DEFENSE_ANIM" in lines[i] and not has_defense_anim:
if "{DEFENSE_ANIM" in line and not has_defense_anim:
has_defense_anim = i
if "[defend]" in lines[i]:
if "[defend]" in line:
in_defend = True
if "[/defend]" in lines[i] or "[attack]" in lines[i]:
if "[/defend]" in line or "[attack]" in line:
in_defend = False
if in_defend and not defend_frame and "[frame]" in lines[i]:
if in_defend and not defend_frame and "[frame]" in line:
defend_frame = i
else:
fields = parse_attribute(lines[i])
fields = parse_attribute(line)
if fields is None:
continue
(key, prefix, value, comment) = fields
@ -1130,30 +1130,30 @@ def hack_syntax(filename, lines):
animations = []
attackname = None
attackline = None
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
elif "[female]" in lines[i]:
elif "[female]" in line:
in_female = True
elif "[/female]" in lines[i]:
elif "[/female]" in line:
in_female = False
elif "[variation]" in lines[i]:
elif "[variation]" in line:
variation_index += 1
in_variation = True
elif "[/variation]" in lines[i]:
elif "[/variation]" in line:
in_variation = False
elif "[unit]" in lines[i]:
elif "[unit]" in line:
in_attack = in_animation = in_female = in_variation = False
female_attack_index = -1
variation_index = 0
male_attack_start = len(animations)
elif "[attack]" in lines[i]:
elif "[attack]" in line:
in_attack = True;
attackname = None
attackline = i
if in_female:
female_attack_index += 1
elif "[animation]" in lines[i] and in_attack:
elif "[animation]" in line and in_attack:
#if verbose:
# print('"%s", line %d: [animation] within [attack]' %
# (filename, i+1))
@ -1173,13 +1173,13 @@ def hack_syntax(filename, lines):
variation = None
animations.append(anim_frame(attackline, attackname, i, in_female, variation))
in_animation = True
elif "[/animation]" in lines[i] and in_attack:
elif "[/animation]" in line and in_attack:
in_animation = False
if animations and animations[-1].animstart != None and animations[-1].animend == None:
animations[-1].animend = i
else:
print('"%s", line %d: [animation] ending here may be ill-formed'%(filename, i+1))
elif "[/attack]" in lines[i]:
elif "[/attack]" in line:
inattack = False;
attackname = None
if animations and (animations[-1].attackstart == None or animations[-1].attackend != None):
@ -1196,8 +1196,8 @@ def hack_syntax(filename, lines):
# Only pick up the *first* name field in an attack block;
# by convention, it will be right after the opening [attack] tag
elif in_attack and not in_animation and not attackname:
#print(filename + ":" + repr(i+1) + ";" + repr(lines[i]))
fields = lines[i].strip().split('#')
#print(filename + ":" + repr(i+1) + ";" + repr(line))
fields = line.strip().split('#')
syntactic = fields[0]
comment = ""
if len(fields) > 1:
@ -1236,8 +1236,8 @@ def hack_syntax(filename, lines):
female_attacks.reverse()
if female_attacks:
female_end = -1
for i in range(len(lines)):
if lines[i].rstrip().endswith("[/female]"):
for i, line in enumerate(lines):
if line.rstrip().endswith("[/female]"):
female_end = i
break
assert female_end != -1
@ -1247,10 +1247,10 @@ def hack_syntax(filename, lines):
male_attacks.reverse()
if male_attacks:
male_end = -1
for i in range(len(lines)):
for i, line in enumerate(lines):
# Male attacks go either before the [female] tag or just
# before the closing [/unit]
if lines[i].rstrip().endswith("[/unit]") or lines[i].rstrip().endswith("[female]"):
if line.rstrip().endswith("[/unit]") or line.rstrip().endswith("[female]"):
male_end = i
break
assert male_end != -1
@ -1260,8 +1260,8 @@ def hack_syntax(filename, lines):
for animation in animations:
if animation.variation != None:
vcount = 0
for j in range(len(lines)):
if "[/variation]" in lines[j]:
for j, line in enumerate(lines):
if "[/variation]" in line:
vcount += 1
if vcount == animation.variation:
break
@ -1285,27 +1285,27 @@ def hack_syntax(filename, lines):
in_effect = False
attackname = None
converting = False
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
elif "[effect]" in lines[i]:
elif "[effect]" in line:
in_effect = True
elif "apply_to=new_attack" in lines[i]:
elif "apply_to=new_attack" in line:
converting = True
elif "[/effect]" in lines[i]:
elif "[/effect]" in line:
converting = in_effect = False
elif in_effect and not attackname:
#print(filename + ":" + repr(i+1) + ";" + repr(lines[i]))
fields = lines[i].strip().split('#')
#print(filename + ":" + repr(i+1) + ";" + repr(line))
fields = line.strip().split('#')
syntactic = fields[0]
comment = ""
if len(fields) > 1:
comment = fields[1]
if syntactic.strip().startswith("name"):
attackname = syntactic.split("=")[1].strip()
elif converting and "[animation]" in lines[i]:
elif converting and "[animation]" in line:
print('"%s", line %d: converting [animation] in [effect] '%(filename, i+1))
ws = leader(lines[i])
ws = leader(line)
outer = outdent(ws)
assert attackname != None
before = outer + "[/effect]\n" \
@ -1315,29 +1315,29 @@ def hack_syntax(filename, lines):
+ ws + baseindent*2 + "name=" + attackname + "\n" \
+ ws + baseindent + "[/attack_filter]\n"
lines[i] = before \
+ lines[i].replace("animation", "attack_anim") \
+ line.replace("animation", "attack_anim") \
+ after
modcount += 1
elif converting and "[/animation]" in lines[i]:
lines[i] = lines[i].replace("animation", "attack_anim")
elif converting and "[/animation]" in line:
lines[i] = line.replace("animation", "attack_anim")
# Upconvert ancient ability declarations from 1.x
level = None
abilities = []
specials = []
lastability = None
lastspecial = None
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
if "[unit]" in lines[i]:
if "[unit]" in line:
abilities = []
if "[attack]" in lines[i]:
if "[attack]" in line:
specials = []
elif "[/attack]" in lines[i]:
elif "[/attack]" in line:
if specials:
if verbose:
print("Lifting obsolete specials:", " ".join(specials))
ws = leader(lines[i])
ws = leader(line)
insertion = ws + baseindent + "[specials]\n"
for special in specials:
if special.startswith("plague("):
@ -1351,11 +1351,11 @@ def hack_syntax(filename, lines):
insertion += ws + baseindent + "[/specials]\n"
lines[lastspecial] = insertion
modcount += 1
elif "[/unit]" in lines[i]:
elif "[/unit]" in line:
if abilities:
if verbose:
print("Lifting obsolete abilities:", " ".join(abilities))
ws = leader(lines[i])
ws = leader(line)
insertion = ws + baseindent + "[abilities]\n"
for ability in abilities:
if ability == "leadership":
@ -1372,8 +1372,8 @@ def hack_syntax(filename, lines):
insertion += ws + baseindent + "[/abilities]\n"
lines[lastability] = insertion
modcount += 1
elif lines[i].count("=") == 1:
(tag, value) = lines[i].strip().split("=")
elif line.count("=") == 1:
(tag, value) = line.strip().split("=")
if tag == "level":
level = value
if tag == "ability":
@ -1396,15 +1396,15 @@ def hack_syntax(filename, lines):
postframe = []
begins = []
converting = 0
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
elif "[attack]" in lines[i]:
elif "[attack]" in line:
in_attack = True
elif "[/attack]" in lines[i]:
elif "[/attack]" in line:
if converting:
assert attackname != None
lines[i] = lines[i].replace("/attack", "/attack_anim")
lines[i] = line.replace("/attack", "/attack_anim")
print('"%s", line %d: converting frame in [attack]'%(filename, converting+1))
ws = leader(lines[converting])
outer = outdent(ws)
@ -1445,11 +1445,11 @@ def hack_syntax(filename, lines):
in_frame = False
postframe = []
begins = []
elif ("[frame]" in lines[i] or "[missile_frame]" in lines[i]) and in_attack and converting == 0:
elif ("[frame]" in line or "[missile_frame]" in line) and in_attack and converting == 0:
converting = i
in_frame = True
elif in_attack:
fields = lines[i].strip().split('#')
fields = line.strip().split('#')
syntactic = fields[0]
comment = ""
if len(fields) > 1:
@ -1465,23 +1465,23 @@ def hack_syntax(filename, lines):
elif in_frame and syntactic.strip().startswith("begin"):
begins.append((syntactic.split("=")[1].strip(), i))
# Ignore sound tags, and their contents, within [attack]
if "[sound]" in lines[i]:
if "[sound]" in line:
print('"%s", line %d: [sound] within [attack] discarded (path will be saved)' %
(filename, i+1))
in_sound = True
modcount += 1
if "[/sound]" in lines[i]:
if "[/sound]" in line:
lines[i] = ""
in_sound = False
if in_sound:
lines[i] = ""
# Move post-frame lines up
if "[frame]" in lines[i] or "[missile_frame]" in lines[i]:
if "[frame]" in line or "[missile_frame]" in line:
in_frame = True
elif "[/frame]" in lines[i] or "[/missile_frame]" in lines[i]:
elif "[/frame]" in line or "[/missile_frame]" in line:
in_frame = False
elif converting and not in_frame:
postframe.append(lines[i])
postframe.append(line)
lines[i] = ""
# Upconvert old radius usage
if upconvert and "1.3.7" in versions and "older" not in versions:
@ -1527,13 +1527,13 @@ def hack_syntax(filename, lines):
frame_commented = in_death_commented = False
frame_start = frame_end = None
image = None
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
elif "[death]" in lines[i]:
elif "[death]" in line:
in_death = i
in_death_commented = lines[i].strip().startswith("#")
elif "[/death]" in lines[i]:
in_death_commented = line.strip().startswith("#")
elif "[/death]" in line:
if frame_start is None:
print('"%s", %d: [death] with no frames' % (filename, i), file=sys.stderr)
continue
@ -1547,7 +1547,7 @@ def hack_syntax(filename, lines):
(filename, i), file=sys.stderr)
continue
# Modify the death wrapper
lines[i] = lines[i].replace("death", "animation")
lines[i] = line.replace("death", "animation")
inner = leader(lines[in_death])+baseindent
if in_death_commented:
inner = "#" + inner
@ -1565,14 +1565,14 @@ def hack_syntax(filename, lines):
inner + "alpha=1~0\n" + \
inner + "image=" + image + "\n" + \
outer + "[/frame]\n"
lines[i] = insertion + lines[i]
lines[i] = insertion + line
in_death = frame_start = frame_end = None
frame_commented = in_death_commented = False
modcount += 1
elif in_death and "[frame]" in lines[i]:
elif in_death and "[frame]" in line:
frame_start = i
frame_commented = lines[i].strip().startswith("#")
elif in_death and "[/frame]" in lines[i]:
frame_commented = line.strip().startswith("#")
elif in_death and "[/frame]" in line:
frame_end = i
# Check for duplicated attack names -- may be a result of a naive
# boucman conversion.
@ -1607,37 +1607,37 @@ start_time=-150
[/attack_filter]
[/attack_anim]\
"""
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
m = re.search(r"(\s+)image_short=(.*)", lines[i])
m = re.search(r"(\s+)image_short=(.*)", line)
if m:
image_block = expanded.replace("\n", "\n" + m.group(1)) + "\n"
lines[i] = m.group(1) + image_block % (m.group(2), "melee")
modcount += 1
m = re.search(r"(\s+)image_long=(.*)", lines[i])
m = re.search(r"(\s+)image_long=(.*)", line)
if m:
image_block = expanded.replace("\n", "\n" + m.group(1)) + "\n"
lines[i] = m.group(1) + image_block % (m.group(2), "ranged")
modcount += 1
# In [terrain], letter= to terrain=
in_terrain = False
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
if "[terrain]" in lines[i]:
if "[terrain]" in line:
in_terrain = True
if "[/terrain]" in lines[i]:
if "[/terrain]" in line:
in_terrain = False
if in_terrain:
lines[i] = lines[i].replace("letter", "terrain")
lines[i] = line.replace("letter", "terrain")
# Upgrade old UNIT macro to 1.4's LOYAL_UNIT
for i in range(len(lines)):
if "no-syntax-rewrite" in lines[i]:
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
if '{UNIT ' in lines[i]:
old = lines[i].strip()
(new, num) = re.subn(r'{UNIT +(\([^)]*\)|"[^"]*"|[^(" ][^ ]*) +(\([^)]*\)|"[^"]*"|[^(" ][^ ]*) +(\([^)]*\)|_? *"[^"]*"|_? *[^(" ][^ ]*) +([0-9]+) +([0-9]+|[^ ]*\$[^ ]*x[^ ]*|\(?{[A-Z0-9_]*X[A-Z0-9_]*}\)?) +([0-9]+|[^ ]*\$[^ ]*y[^ ]*|\(?{[A-Z0-9_]*Y[A-Z0-9_]*}\)?)}', r'{LOYAL_UNIT \4 \1 \5 \6 \2 \3}', lines[i])
if '{UNIT ' in line:
old = line.strip()
(new, num) = re.subn(r'{UNIT +(\([^)]*\)|"[^"]*"|[^(" ][^ ]*) +(\([^)]*\)|"[^"]*"|[^(" ][^ ]*) +(\([^)]*\)|_? *"[^"]*"|_? *[^(" ][^ ]*) +([0-9]+) +([0-9]+|[^ ]*\$[^ ]*x[^ ]*|\(?{[A-Z0-9_]*X[A-Z0-9_]*}\)?) +([0-9]+|[^ ]*\$[^ ]*y[^ ]*|\(?{[A-Z0-9_]*Y[A-Z0-9_]*}\)?)}', r'{LOYAL_UNIT \4 \1 \5 \6 \2 \3}', line)
if num > 0:
lines[i] = new
print('"%s", line %d: %s -> %s' % (filename, i+1, old, new.strip()))
@ -1658,11 +1658,11 @@ def is_map(filename):
with codecs.open(filename, "r", "utf8") as fp:
lines = fp.readlines()
has_map_content = False
for i in range(len(lines)):
if lines[i].endswith("\n"):
lines[i] = lines[i][:-1]
if lines[i].endswith("\r"):
lines[i] = lines[i][:-1]
for i, line in enumerate(lines):
if line.endswith("\n"):
lines[i] = line[:-1]
if line.endswith("\r"):
lines[i] = line[:-1]
w = len(lines[0])
for line in lines:
if len(line) != w:
@ -1956,17 +1956,17 @@ def translator(filename, mapxforms, textxform, versions):
linecount = 1
startline = None
depth = quotecount = 0
for i in range(len(transformed)):
if transformed[i] == '\n':
for i, char in enumerate(transformed):
if char == '\n':
linecount += 1
elif transformed[i] == '{':
elif char == '{':
if depth == 0:
unclosed = startline = linecount
quotecount = 0
depth += 1
elif transformed[i] == '"':
elif char == '"':
quotecount += 1
elif transformed[i] == '}':
elif char == '}':
depth -= 1
if depth == 0:
unclosed = None