Fix wmlindent quote detection (#6764)

* wmlindent: Fix parsing quotes in comments

* Remove unnecessary wmlindent ignores

* Run wmlindent
This commit is contained in:
Celtic Minstrel 2022-06-18 03:37:55 -04:00 committed by Celtic Minstrel
parent 585f671557
commit 8ee5cdf092
4 changed files with 25 additions and 35 deletions

View file

@ -346,7 +346,6 @@
message= _ "<span color='#A00000'>Important:</span> The animal Micro AIs in this scenario are written for a number of animal unit types that do not exist in Wesnoth mainline, such as sheep, sheep dogs, or deer. In this test scenario, these units have been replaced by mainline units."
[/message]
# wmlindent: start ignoring
[message]
speaker=narrator
image=wesnoth-icon.png
@ -354,7 +353,6 @@
"+{ANIMAL_AI_DESCRIPTIONS1}
[/message]
# wmlindent: stop ignoring
[message]
speaker=narrator
image=wesnoth-icon.png
@ -366,13 +364,11 @@
caption= _ "Question for the Player"
image=wesnoth-icon.png
# wmllint: unbalanced-on
# wmlindent: start ignoring
message= _ "It is possible to include a human-controlled Side 1, so that the action stops once every turn for looking around (or to mess with things in debug mode).
Note that there is no end to this scenario. For demonstration purposes, any unit that is killed is replaced by another unit of the same type at the beginning of the next turn. In order to end the scenario, there's a right-click option - but that only works in human-controlled mode. In AI-only mode, you have to press 'Esc' or reload a previous savefile.
Also note: The Animal AIs are coded as Micro AIs. A Micro AI can be added and adapted to the need of a scenario easily using only WML and the [micro_ai] tag. Check out the <span color='#00A000'>Micro AI wiki page</span> at https://wiki.wesnoth.org/Micro_AIs for more information." # wmllint: no spellcheck
# wmlindent: stop ignoring
# wmllint: unbalanced-off
[option]
label= _ "<span font='16'>I'll just watch the animals.</span>"
@ -426,13 +422,11 @@ Also note: The Animal AIs are coded as Micro AIs. A Micro AI can be added and ad
type=Wolf
[/filter_second]
# wmlindent: start ignoring
[message]
speaker=$second_unit.id
message= _ "Yowl!
Translation: Those boars are mean! We better stay away from them and their young."
[/message]
# wmlindent: stop ignoring
[micro_ai]
side=6

View file

@ -1,5 +1,4 @@
#textdomain wesnoth
#wmlindent: start ignoring
# This file needs to be processed *after* all others in this directory
#
# The following flags are defined to have a meaning
@ -547,7 +546,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:BASE Ior interior/wood-ruined LAYER=-284 FLAG=raised_base}
{NEW:BASE Irs,Icr interior/stone-regular LAYER=-284 FLAG=raised_base}
# Water base terrains
{NEW:OVERLAY Wwf water/ford FLAG=ford LAYER=-519}
@ -682,7 +680,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:CASTLEWALL2 Koa !,Ket,!,C*,Ke* (!,C*,K*,Xu*,Xo*) castle/winter-orcish/keep-fort}
{NEW:CASTLEWALL Koa (Ke,Kea,!,K*,Xu*,Xo*) K* castle/winter-orcish/keep}
# Desert castles
{NEW:CASTLEWALL Cd (!,C*,K*,Xu*,Xo*) !,Ket,!,C*,Ke* castle/sand/castle}
@ -705,7 +702,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:CASTLEWALL2 Kha !,Ket,!,C*,Ke* (!,C*,K*,Xu*,Xo*) castle/snowy/keep-castle}
{NEW:CASTLEWALL Kha (Ke,Kea,!,K*,Xu*,Xo*) K* castle/snowy/keep}
# sunken/swamp ruins (submerged part)
# Show sunken graphics for sunken castle only when next to water terrain
# Show sunken graphics for sunken/swamp keep also when next to swamp
@ -746,7 +742,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:CASTLEWALL2 Ket (!,Ket,!,C*,Ke*) (!,C*,K*,Xu*,Xo*) castle/encampment/tall-keep-castle}
{NEW:CASTLEWALL Ket (!,Ket,!,Ke*,!,K*,Xu*,Xo*) K* castle/encampment/tall-keep}
# Castle & Encampment Base Transtions
{NEW:TRANSITION !,Kfa,Cfa,!,C*,K* Kfa,Cfa -79 castle/winter-dwarven/dwarven-castle-floor FLAG=inside}
@ -949,12 +944,10 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:TRANSITION Gg Gs,Gd,Gll -256 grass/green-long}
{NEW:TRANSITION Gs Gg,Gd,Gll -257 grass/semi-dry-long}
{NEW:TRANSITION Gs (R*,D*,Aa,Ur,Urc,Ias) -260 grass/semi-dry-medium}
{NEW:TRANSITION Gg (R*,D*,Aa,Ur,Urc,Ias) -261 grass/green-medium}
{NEW:TRANSITION Gd (R*,D*,Aa,Ur,Urc,Ias) -262 grass/dry-medium}
{NEW:TRANSITION Gll (!,Gll,Q*,W*,Ai,C*,K*) -270 grass/leaf-litter}
{NEW:TRANSITION (Gg*,Qx*) (!,Gg*,Q*,Mm,Ms,Hh,C*,K*) -271 grass/green-abrupt}
{NEW:TRANSITION Gs (!,Gs,Q*,C*,K*) -272 grass/semi-dry-abrupt}
@ -987,7 +980,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:TRANSITION Ds (!,Ds,W*,S*,Ai,Q*) -510 sand/beach}
{NEW:TRANSITION Dd (!,R*,Dd,W*,S*,Ai,Q*) -510 sand/desert}
# Dirt transitions are double sided
{NEW:TRANSITION (!,Rd,Rr*,Hh*,M*,Q*,D*,T*) Rd -370 flat/desert-road FLAG=inside}
{NEW:TRANSITION Rd (!,Rd,W*,Ai,Q*,D*,T*) -371 flat/desert-road}
@ -1001,7 +993,6 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
{NEW:TRANSITION Rb Ias -384 flat/dirt-dark FLAG=inside}
{NEW:TRANSITION Ias Rb -388 flat/dirt-dark}
# This complicated part keeps the submerged part of ice or a bank from drawing over the above-water parts of banks or ice
{NEW:TRANSITION (!,Chw,Khw,Khs,!,C*,K*) (Ai,W*) -480 castle/castle-to-ice FLAG=non_submerged}
@ -1063,6 +1054,3 @@ C*,K*,X*,Q*,W*,Ai,M*,*^V*,*^B*,_off^_usr#enddef
# Default terrain
{NEW:BASE * void/void}
#wmlindent: stop ignoring

View file

@ -2599,7 +2599,6 @@ Also, 0..9 = $below_ten, one,two,three = $ascii and the bonus answer is $mixed."
x,y,side=17,9,1
[/filter]
#wmlindent: start ignoring
[message]
speaker=unit
message=_"Battle for Wesnoth Users Manual
@ -2639,7 +2638,6 @@ In the world of Wesnoth there dwell humans, elves, dwarves, orcs, drakes, sauria
For game purposes, the races group into factions; for example, orcs often cooperate with trolls, and elves or dwarves with humans. Some other factions reflect divisions within human society — loyalists vs. outlaws, for example. In most campaigns, you will control units drawn a single faction. But sometimes factions make alliances with others, so you may face more than one faction in a scenario."
[/message]
#wmlindent: stop ignoring
[/event]
{PLACE_IMAGE items/book1.png 2 2}
@ -2689,7 +2687,6 @@ For game purposes, the races group into factions; for example, orcs often cooper
[modify_side]
side=1
#wmlindent: start ignoring
shroud_data="|111111111111
|1111111111111
|1111111111111
@ -2728,7 +2725,6 @@ For game purposes, the races group into factions; for example, orcs often cooper
|000000000000000111111
|00000000000000011111
"
#wmlindent: stop ignoring
[/modify_side]
[/event]
@ -3420,7 +3416,6 @@ For game purposes, the races group into factions; for example, orcs often cooper
[terrain_mask]
x,y=20,1
border=no
#wmlindent: start ignoring
mask="
_s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s
_s, _s, _s, Aa, Aa, Aa, Aa, _s, _s, _s
@ -3433,7 +3428,6 @@ _s, _s, Aa, Aa, Aa, Aa, Aa, Aa, _s, _s
_s, _s, _s, Aa, Aa, Aa, Aa, _s, _s, _s
_s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s
"
#wmlindent: stop ignoring
[rule]
old=Gg^Vh
new=Aa
@ -3478,14 +3472,12 @@ _s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s
[terrain_mask]
x,y=8,11
border=no
#wmlindent: start ignoring
mask="
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
^Ft, ^Ft, ^Ft, ^Ft
"
#wmlindent: stop ignoring
[rule]
old=*^F*
layer=overlay
@ -3519,14 +3511,12 @@ _s, _s, _s, _s, Aa, Aa, _s, _s, _s, _s
[terrain_mask]
x,y=8,11
border=no
#wmlindent: start ignoring
mask="
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
Ww, Ww, Ww, Ww
"
#wmlindent: stop ignoring
[rule]
old=*^Ve*
layer=base
@ -3595,13 +3585,11 @@ Ww, Ww, Ww, Ww
[/message]
[message]
speaker=narrator
#wmlindent: start ignoring
message="Formula:
<span color='green'> $formula</span>
Result:
<span color='red'> $(debug_print( 'Result: ', ($formula) ))</span>
"
#wmlindent: stop ignoring
[/message]
[/command]
[/set_menu_item]

View file

@ -103,6 +103,29 @@ class bailout(Exception):
self.lineno = lineno
self.msg = msg
def strip_comment(line, in_string):
"""
Strip a trailing comment from a line, if present.
Allows for unbalanced quotes, where comment characters are literal.
"""
if not line:
return line
split = line.split('"')
result = split[0]
if not in_string and '#' in result:
return result.split('#')[0].rstrip();
split.pop(0)
for component in split:
in_string = not in_string
result += '"'
# If we end up outside a string and there's a comment, we're done
if not in_string and '#' in component:
result += component.split('#')[0]
break
else:
result += component
return result.rstrip()
def reindent(name, infp, outfp):
"Reindent WML."
dostrip = True
@ -208,10 +231,7 @@ def reindent(name, infp, outfp):
instring = False
# Compute the dostrip state likewise.
# We look for unbalanced string quotes.
if dostrip:
eligible = re.split("\s#", transformed)[0]
else:
eligible = transformed
eligible = strip_comment(transformed, not dostrip)
if dostrip and "<<" in eligible and not ">>" in eligible.split("<<", 1)[1]:
dostrip = False
in_lua = True
@ -228,7 +248,7 @@ def reindent(name, infp, outfp):
lasttag = ""
# Pure macro files look like they have unbalanced indents. That's OK
if indent_level != 0 and seen_wml:
print('wmlindent: "%s". line %d: end of file with indent nonzero.' % (name, countlines), file=sys.stderr)
print('wmlindent: "%s". line %d: end of file with indent nonzero (%d).' % (name, countlines, indent_level), file=sys.stderr)
def allwmlfiles(directory):
"Get names of all WML files under dir, or dir itself if not a directory."