-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmllint111
2537 lines (2483 loc) · 116 KB
/
wmllint111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# encoding: utf8
#
# wmllint -- check WML for conformance to the most recent dialect
#
# By Eric S. Raymond April 2007.
#
# All conversion logic for lifting WML and maps from older versions of the
# markup to newer ones should live here. This includes resource path changes
# and renames, also map format conversions.
#
# Note: Lift logic for pre-1.4 versions has been removed; if you need
# it, check out a copy of wmllint from the 1.4 stable branch and use
# that to lift before running this one. I did this for a policy
# reason; I wanted to kill off the --oldversion switch. It will *not*
# be restored; in future, changes to WML syntax *must* be forward
# compatible in such a way that tags from old versions can be
# unambiguously recognized (this will save everybody heartburn). As a
# virtuous side effect, this featurectomy cuts wmllint's code
# complexity by over 50%, improves performance by about 33%, and
# banishes some annoying behaviors related to the 1.2 map-conversion
# code.
#
# While the script is at it, it checks for various incorrect and dodgy WML
# constructs, including:
# * unbalanced tags
# * strings that need a translation mark and should not have them
# * strings that have a translation mark and should not
# * translatable strings containing macro references
# * filter references by id= not matched by an actual unit
# * abilities or traits without matching special notes, or vice-versa
# * consistency between recruit= and recruitment_pattern= instances
# * unknown unit types in recruitment lists
# * double space after punctuation in translatable strings.
# * unknown races or movement types in units
# * unknown base units
# * misspellings in message and description strings
#
# Takes any number of directories as arguments. Each directory is converted.
# If no directories are specified, acts on the current directory.
#
# The recommended procedure is this:
# 1. Run it with --dryrun first to see what it will do.
# 2. If the messages look good, run without --dryrun; the old content
# will be left in backup files with a -bak extension.
# 3. Eyeball the changes with the --diff option.
# 4. Use wmlscope, with a directory list including the Wesnoth mainline WML
# as first argument, to check that you have no unresolved references.
# 5. Test the conversion.
# 6. Use either --clean to remove the -bak files or --revert to
# undo the conversion.
#
# If you would like wmllint to generate usage=mask instead of usage=map in
# your mask files, you *must* name them with the .mask extension.
#
# Note: You can shut wmllint up about custom terrains by having a comment
# on the same line that includes the string "wmllint: ignore" or
# "wmllint: noconvert". The same magic comments will also disable checking
# of translation marks.
#
# You can also prevent description insertions with "wmllint: no-icon".
#
# You can force otherwise undeclared characters to be recognized with
# a magic comment containing the string "wmllint: recognize".
# The rest of the line is stripped and treated as the name of a character
# who should be recognized in descriptions. This will be useful,
# for example, if your scenario follows a continue so there are
# characters present who were not explicitly recalled. It may
# also be useful if you have wrapped unit-creation or recall markup in
# non-core macros and wmllint cannot recognize it.
#
# Similarly, it is possible to explicitly declare a unit's usage class
# with a magic comment that looks like this:
# wmllint: usage of <unit> is <class>
# Note that <unit> must be a string wrapped in ASCII doublequotes. This
# declaration will be useful if you are declaring units with macros that
# include a substitutable formal in the unit name; there are examples in UtBS.
#
# If your recruitment patterns include any usage classes besides the standard
# recruitable classes, you can tell wmllint about them with the magic comment
# "wmllint: usagetype". If you have more than one, this comment is
# comma-separable, and can even be pluralized, for example:
# wmllint: usagetypes stonegazer, statue
# This comment should be added in a file that wmllint checks before the
# non-standard usage class appears in a scenario, preferably the _main.cfg.
# (Adding it to the file of a unit generally won't work, because wmllint
# checks the directory's /units subfolder after /scenarios, alphabetically.)
#
# You can disable stack-based malformation checks with a comment
# containing "wmllint: validate-off" and re-enable with "wmllint: validate-on".
#
# You can prevent filename conversions with a comment containing
# "wmllint: noconvert" on the same line as the filename.
#
# You can suppress complaints about files without an initial textdomain line
# by embedding the magic comment "# wmllint: no translatables" in the file.
# of course, it's a good idea to be sure this assertion is actually true.
#
# You can skip checks on unbalanced WML (e.g. in a macro definition) by
# bracketing it with "wmllint: unbalanced-on" and "wmllint: unbalanced-off".
# Note that this will also disable stack-based validation on the span
# of lines they enclose.
#
# You can suppress warnings about newlines in messages (and attempts to
# repair them) with "wmllint: display on", and re-enable them with
# "wmllint: display off". The repair attempts (only) may also be
# suppressed with the --stringfreeze option.
#
# A special comment "# wmllint: notecheck off" will disable checking unit types
# for consistency between abilities/weapon specials and usage of special notes
# macros in their descriptions.
# The comment "# wmllint: notecheck on" will re-enable this check.
#
# A special comment "# wmllint: deathcheck off" will disable the check whether
# dying units speak in their death events.
# The comment "# wmllint: deathcheck on" will re-enable this check.
#
# A magic comment of the form "wmllint: general spellings word1
# word2..." will declare the tokens word1, word2, etc. to be
# acceptable spellings for anywhere in the Wesnoth tree that the
# spellchecker should never flag. If the keyword "general" is
# replaced by "local", the spelling exceptions apply only in the
# current file. If the keyword "general" is replaced by "directory",
# the spelling exceptions apply to all files below the parent
# directory.
#
# A comment containing "no spellcheck" disables spellchecking on the
# line where it occurs.
#
# A comment of the form
#
# #wmllint: match {ABILITY_FOO} with {SPECIAL_NOTES_IOO}
#
# will declare an ability macro and a special-notes macro to be tied
# together for reference-checking purposes.
import sys, os, re, getopt, string, copy, difflib, time, gzip
from wesnoth.wmltools import *
from wesnoth.wmliterator import *
# Changes meant to be done on maps and .cfg lines.
mapchanges = (
("^Voha", "^Voa"),
("^Voh", "^Vo"),
("^Vhms", "^Vhha"),
("^Vhm", "^Vhh"),
("^Vcha", "^Vca"),
("^Vch", "^Vc"),
("^Vcm", "^Vc"),
("Ggf,", "Gg^Emf"),
("Qv,", "Mv"),
)
# Global changes meant to be done on all lines. Suppressed by noconvert.
linechanges = (
("canrecruit=1", "canrecruit=yes"),
("canrecruit=0", "canrecruit=no"),
("generate_description", "generate_name"),
# Fix a common typo
("agression=", "aggression="),
# These changed just after 1.5.0
("[special_filter]", "[filter_attack]"),
("[wml_filter]", "[filter_wml]"),
("[unit_filter]", "[filter]"),
("[secondary_unit_filter]", "[filter_second]"),
("[attack_filter]", "[filter_attack]"),
("[secondary_attack_filter]", "[filter_second_attack]"),
("[special_filter_second]", "[filter_second_attack]"),
("[/special_filter]", "[/filter_attack]"),
("[/wml_filter]", "[/filter_wml]"),
("[/unit_filter]", "[/filter]"),
("[/secondary_unit_filter]", "[/filter_second]"),
("[/attack_filter]", "[/filter_attack]"),
("[/secondary_attack_filter]", "[/filter_second_attack]"),
("[/special_filter_second]", "[/filter_second_attack]"),
("grassland=", "flat="),
("tundra=", "frozen="),
("cavewall=", "impassable="),
("canyon=", "unwalkable="),
# This changed after 1.5.2
("advanceto=", "advances_to="),
# This changed after 1.5.5, to enable mechanical spellchecking
("sabre", "saber"),
("nr-sad.ogg", "sad.ogg"),
# Changed after 1.5.7
("[debug_message]", "[wml_message]"),
("[/debug_message]", "[/wml_message]"),
# Changed just before 1.5.9
("portraits/Alex_Jarocha-Ernst/drake-burner.png",
"portraits/drakes/burner.png"),
("portraits/Alex_Jarocha-Ernst/drake-clasher.png",
"portraits/drakes/clasher.png"),
("portraits/Alex_Jarocha-Ernst/drake-fighter.png",
"portraits/drakes/fighter.png"),
("portraits/Alex_Jarocha-Ernst/drake-glider.png",
"portraits/drakes/glider.png"),
("portraits/Alex_Jarocha-Ernst/ghoul.png",
"portraits/undead/ghoul.png"),
("portraits/Alex_Jarocha-Ernst/mermaid-initiate.png",
"portraits/merfolk/initiate.png"),
("portraits/Alex_Jarocha-Ernst/merman-fighter.png",
"portraits/merfolk/fighter.png"),
("portraits/Alex_Jarocha-Ernst/merman-hunter.png",
"portraits/merfolk/hunter.png"),
("portraits/Alex_Jarocha-Ernst/naga-fighter.png",
"portraits/nagas/fighter.png"),
("portraits/Alex_Jarocha-Ernst/nagini-fighter.png",
"portraits/nagas/fighter+female.png"),
("portraits/Alex_Jarocha-Ernst/orcish-assassin.png",
"portraits/orcs/assassin.png"),
("portraits/Emilien_Rotival/human-general.png",
"portraits/humans/general.png"),
("portraits/Emilien_Rotival/human-heavyinfantry.png",
"portraits/humans/heavy-infantry.png"),
("portraits/Emilien_Rotival/human-ironmauler.png",
"portraits/humans/iron-mauler.png"),
("portraits/Emilien_Rotival/human-lieutenant.png",
"portraits/humans/lieutenant.png"),
("portraits/Emilien_Rotival/human-marshal.png",
"portraits/humans/marshal.png"),
("portraits/Emilien_Rotival/human-peasant.png",
"portraits/humans/peasant.png"),
("portraits/Emilien_Rotival/human-pikeman.png",
"portraits/humans/pikeman.png"),
("portraits/Emilien_Rotival/human-royalguard.png",
"portraits/humans/royal-guard.png"),
("portraits/Emilien_Rotival/human-sergeant.png",
"portraits/humans/sergeant.png"),
("portraits/Emilien_Rotival/human-spearman.png",
"portraits/humans/spearman.png"),
("portraits/Emilien_Rotival/human-swordsman.png",
"portraits/humans/swordsman.png"),
("portraits/Emilien_Rotival/transparent/human-general.png",
"portraits/humans/transparent/general.png"),
("portraits/Emilien_Rotival/transparent/human-heavyinfantry.png",
"portraits/humans/transparent/heavy-infantry.png"),
("portraits/Emilien_Rotival/transparent/human-ironmauler.png",
"portraits/humans/transparent/iron-mauler.png"),
("portraits/Emilien_Rotival/transparent/human-lieutenant.png",
"portraits/humans/transparent/lieutenant.png"),
("portraits/Emilien_Rotival/transparent/human-marshal.png",
"portraits/humans/transparent/marshal.png"),
("portraits/Emilien_Rotival/transparent/human-marshal-2.png",
"portraits/humans/transparent/marshal-2.png"),
("portraits/Emilien_Rotival/transparent/human-peasant.png",
"portraits/humans/transparent/peasant.png"),
("portraits/Emilien_Rotival/transparent/human-pikeman.png",
"portraits/humans/transparent/pikeman.png"),
("portraits/Emilien_Rotival/transparent/human-royalguard.png",
"portraits/humans/transparent/royal-guard.png"),
("portraits/Emilien_Rotival/transparent/human-sergeant.png",
"portraits/humans/transparent/sergeant.png"),
("portraits/Emilien_Rotival/transparent/human-spearman.png",
"portraits/humans/transparent/spearman.png"),
("portraits/Emilien_Rotival/transparent/human-swordsman.png",
"portraits/humans/transparent/swordsman.png"),
("portraits/James_Woo/assassin.png",
"portraits/humans/assassin.png"),
("portraits/James_Woo/dwarf-guard.png",
"portraits/dwarves/guard.png"),
("portraits/James_Woo/orc-warlord.png",
"portraits/orcs/warlord.png"),
("portraits/James_Woo/orc-warlord2.png",
"portraits/orcs/warlord2.png"),
("portraits/James_Woo/orc-warlord3.png",
"portraits/orcs/warlord3.png"),
("portraits/James_Woo/orc-warlord4.png",
"portraits/orcs/warlord4.png"),
("portraits/James_Woo/orc-warlord5.png",
"portraits/orcs/warlord5.png"),
("portraits/James_Woo/troll.png",
"portraits/trolls/troll.png"),
("portraits/Jason_Lutes/human-bandit.png",
"portraits/humans/bandit.png"),
("portraits/Jason_Lutes/human-grand-knight.png",
"portraits/humans/grand-knight.png"),
("portraits/Jason_Lutes/human-halberdier.png",
"portraits/humans/halberdier.png"),
("portraits/Jason_Lutes/human-highwayman.png",
"portraits/humans/highwayman.png"),
("portraits/Jason_Lutes/human-horseman.png",
"portraits/humans/horseman.png"),
("portraits/Jason_Lutes/human-javelineer.png",
"portraits/humans/javelineer.png"),
("portraits/Jason_Lutes/human-knight.png",
"portraits/humans/knight.png"),
("portraits/Jason_Lutes/human-lancer.png",
"portraits/humans/lancer.png"),
("portraits/Jason_Lutes/human-paladin.png",
"portraits/humans/paladin.png"),
("portraits/Jason_Lutes/human-thug.png",
"portraits/humans/thug.png"),
("portraits/Kitty/elvish-archer.png",
"portraits/elves/archer.png"),
("portraits/Kitty/elvish-archer+female.png",
"portraits/elves/archer+female.png"),
("portraits/Kitty/elvish-captain.png",
"portraits/elves/captain.png"),
("portraits/Kitty/elvish-druid.png",
"portraits/elves/druid.png"),
("portraits/Kitty/elvish-fighter.png",
"portraits/elves/fighter.png"),
("portraits/Kitty/elvish-hero.png",
"portraits/elves/hero.png"),
("portraits/Kitty/elvish-high-lord.png",
"portraits/elves/high-lord.png"),
("portraits/Kitty/elvish-lady.png",
"portraits/elves/lady.png"),
("portraits/Kitty/elvish-lord.png",
"portraits/elves/lord.png"),
("portraits/Kitty/elvish-marksman.png",
"portraits/elves/marksman.png"),
("portraits/Kitty/elvish-marksman+female.png",
"portraits/elves/marksman+female.png"),
("portraits/Kitty/elvish-ranger.png",
"portraits/elves/ranger.png"),
("portraits/Kitty/elvish-ranger+female.png",
"portraits/elves/ranger+female.png"),
("portraits/Kitty/elvish-scout.png",
"portraits/elves/scout.png"),
("portraits/Kitty/elvish-shaman.png",
"portraits/elves/shaman.png"),
("portraits/Kitty/elvish-shyde.png",
"portraits/elves/shyde.png"),
("portraits/Kitty/elvish-sorceress.png",
"portraits/elves/sorceress.png"),
("portraits/Kitty/human-dark-adept.png",
"portraits/humans/dark-adept.png"),
("portraits/Kitty/human-dark-adept+female.png",
"portraits/humans/dark-adept+female.png"),
("portraits/Kitty/human-mage.png",
"portraits/humans/mage.png"),
("portraits/Kitty/human-mage+female.png",
"portraits/humans/mage+female.png"),
("portraits/Kitty/human-mage-arch.png",
"portraits/humans/mage-arch.png"),
("portraits/Kitty/human-mage-arch+female.png",
"portraits/humans/mage-arch+female.png"),
("portraits/Kitty/human-mage-light.png",
"portraits/humans/mage-light.png"),
("portraits/Kitty/human-mage-light+female.png",
"portraits/humans/mage-light+female.png"),
("portraits/Kitty/human-mage-red.png",
"portraits/humans/mage-red.png"),
("portraits/Kitty/human-mage-red+female.png",
"portraits/humans/mage-red+female.png"),
("portraits/Kitty/human-mage-silver.png",
"portraits/humans/mage-silver.png"),
("portraits/Kitty/human-mage-silver+female.png",
"portraits/humans/mage-silver+female.png"),
("portraits/Kitty/human-mage-white.png",
"portraits/humans/mage-white.png"),
("portraits/Kitty/human-mage-white+female.png",
"portraits/humans/mage-white+female.png"),
("portraits/Kitty/human-necromancer.png",
"portraits/humans/necromancer.png"),
("portraits/Kitty/human-necromancer+female.png",
"portraits/humans/necromancer+female.png"),
("portraits/Kitty/troll-whelp.png",
"portraits/trolls/whelp.png"),
("portraits/Kitty/undead-lich.png",
"portraits/undead/lich.png"),
("portraits/Kitty/transparent/elvish-archer.png",
"portraits/elves/transparent/archer.png"),
("portraits/Kitty/transparent/elvish-archer+female.png",
"portraits/elves/transparent/archer+female.png"),
("portraits/Kitty/transparent/elvish-captain.png",
"portraits/elves/transparent/captain.png"),
("portraits/Kitty/transparent/elvish-druid.png",
"portraits/elves/transparent/druid.png"),
("portraits/Kitty/transparent/elvish-fighter.png",
"portraits/elves/transparent/fighter.png"),
("portraits/Kitty/transparent/elvish-hero.png",
"portraits/elves/transparent/hero.png"),
("portraits/Kitty/transparent/elvish-high-lord.png",
"portraits/elves/transparent/high-lord.png"),
("portraits/Kitty/transparent/elvish-lady.png",
"portraits/elves/transparent/lady.png"),
("portraits/Kitty/transparent/elvish-lord.png",
"portraits/elves/transparent/lord.png"),
("portraits/Kitty/transparent/elvish-marksman.png",
"portraits/elves/transparent/marksman.png"),
("portraits/Kitty/transparent/elvish-marksman+female.png",
"portraits/elves/transparent/marksman+female.png"),
("portraits/Kitty/transparent/elvish-ranger.png",
"portraits/elves/transparent/ranger.png"),
("portraits/Kitty/transparent/elvish-ranger+female.png",
"portraits/elves/transparent/ranger+female.png"),
("portraits/Kitty/transparent/elvish-scout.png",
"portraits/elves/transparent/scout.png"),
("portraits/Kitty/transparent/elvish-shaman.png",
"portraits/elves/transparent/shaman.png"),
("portraits/Kitty/transparent/elvish-shyde.png",
"portraits/elves/transparent/shyde.png"),
("portraits/Kitty/transparent/elvish-sorceress.png",
"portraits/elves/transparent/sorceress.png"),
("portraits/Kitty/transparent/human-dark-adept.png",
"portraits/humans/transparent/dark-adept.png"),
("portraits/Kitty/transparent/human-dark-adept+female.png",
"portraits/humans/transparent/dark-adept+female.png"),
("portraits/Kitty/transparent/human-mage.png",
"portraits/humans/transparent/mage.png"),
("portraits/Kitty/transparent/human-mage+female.png",
"portraits/humans/transparent/mage+female.png"),
("portraits/Kitty/transparent/human-mage-arch.png",
"portraits/humans/transparent/mage-arch.png"),
("portraits/Kitty/transparent/human-mage-arch+female.png",
"portraits/humans/transparent/mage-arch+female.png"),
("portraits/Kitty/transparent/human-mage-light.png",
"portraits/humans/transparent/mage-light.png"),
("portraits/Kitty/transparent/human-mage-light+female.png",
"portraits/humans/transparent/mage-light+female.png"),
("portraits/Kitty/transparent/human-mage-red.png",
"portraits/humans/transparent/mage-red.png"),
("portraits/Kitty/transparent/human-mage-red+female.png",
"portraits/humans/transparent/mage-red+female.png"),
("portraits/Kitty/transparent/human-mage-silver.png",
"portraits/humans/transparent/mage-silver.png"),
("portraits/Kitty/transparent/human-mage-silver+female.png",
"portraits/humans/transparent/mage-silver+female.png"),
("portraits/Kitty/transparent/human-mage-white.png",
"portraits/humans/transparent/mage-white.png"),
("portraits/Kitty/transparent/human-mage-white+female.png",
"portraits/humans/transparent/mage-white+female.png"),
("portraits/Kitty/transparent/human-necromancer.png",
"portraits/humans/transparent/necromancer.png"),
("portraits/Kitty/transparent/human-necromancer+female.png",
"portraits/humans/transparent/necromancer+female.png"),
("portraits/Kitty/transparent/troll-whelp.png",
"portraits/trolls/transparent/whelp.png"),
("portraits/Kitty/transparent/undead-lich.png",
"portraits/undead/transparent/lich.png"),
("portraits/Nicholas_Kerpan/human-poacher.png",
"portraits/humans/poacher.png"),
("portraits/Nicholas_Kerpan/human-thief.png",
"portraits/humans/thief.png"),
("portraits/Other/brown-lich.png",
"portraits/undead/brown-lich.png"),
("portraits/Other/cavalryman.png",
"portraits/humans/cavalryman.png"),
("portraits/Other/human-masterbowman.png",
"portraits/humans/master-bowman.png"),
("portraits/Other/scorpion.png",
"portraits/monsters/scorpion.png"),
("portraits/Other/sea-serpent.png",
"portraits/monsters/sea-serpent.png"),
("portraits/Pekka_Aikio/human-bowman.png",
"portraits/humans/bowman.png"),
("portraits/Pekka_Aikio/human-longbowman.png",
"portraits/humans/longbowman.png"),
("portraits/Philip_Barber/dwarf-dragonguard.png",
"portraits/dwarves/dragonguard.png"),
("portraits/Philip_Barber/dwarf-fighter.png",
"portraits/dwarves/fighter.png"),
("portraits/Philip_Barber/dwarf-lord.png",
"portraits/dwarves/lord.png"),
("portraits/Philip_Barber/dwarf-thunderer.png",
"portraits/dwarves/thunderer.png"),
("portraits/Philip_Barber/saurian-augur.png",
"portraits/saurians/augur.png"),
("portraits/Philip_Barber/saurian-skirmisher.png",
"portraits/saurians/skirmisher.png"),
("portraits/Philip_Barber/undead-death-knight.png",
"portraits/undead/death-knight.png"),
("portraits/Philip_Barber/transparent/dwarf-dragonguard.png",
"portraits/dwarves/transparent/dragonguard.png"),
("portraits/Philip_Barber/transparent/dwarf-fighter.png",
"portraits/dwarves/transparent/fighter.png"),
("portraits/Philip_Barber/transparent/dwarf-lord.png",
"portraits/dwarves/transparent/lord.png"),
("portraits/Philip_Barber/transparent/dwarf-thunderer.png",
"portraits/dwarves/transparent/thunderer.png"),
("portraits/Philip_Barber/transparent/saurian-augur.png",
"portraits/saurians/transparent/augur.png"),
("portraits/Philip_Barber/transparent/saurian-skirmisher.png",
"portraits/saurians/transparent/skirmisher.png"),
("portraits/Philip_Barber/transparent/undead-death-knight.png",
"portraits/undead/transparent/death-knight.png"),
# Changed just before 1.5.11
("titlescreen/landscapebattlefield.jpg",
"story/landscape-battlefield.jpg"),
("titlescreen/landscapebridge.jpg",
"story/landscape-bridge.jpg"),
("titlescreen/landscapecastle.jpg",
"story/landscape-castle.jpg"),
("LABEL_PERSISTANT", "LABEL_PERSISTENT"),
# Changed just before 1.5.13
("targetting", "targeting"),
# Changed just after 1.7 fork
("[stone]", "[petrify]"),
("[unstone]", "[unpetrify]"),
("[/stone]", "[/petrify]"),
("[/unstone]", "[/unpetrify]"),
("WEAPON_SPECIAL_STONE", "WEAPON_SPECIAL_PETRIFY"),
("SPECIAL_NOTE_STONE", "SPECIAL_NOTE_PETRIFY"),
(".stoned", ".petrified"),
("stoned=", "petrified="),
# Changed at rev 37390
("swing=", "value_second="),
# Changed just before 1.7.3
("Drake Gladiator", "Drake Thrasher"),
("gladiator-", "thrasher-"),
("Drake Slasher", "Drake Arbiter"),
("slasher-", "arbiter-"),
# Changes after 1.7.5
("portraits/nagas/fighter+female.png", "portraits/nagas/fighter.png"),
# Changes after 1.8rc1
("portraits/orcs/warlord.png", "portraits/orcs/transparent/warlord.png"),
#("portraits/orcs/warlord2.png","portraits/orcs/transparent/warlord.png"), # see 1.11.3
("portraits/orcs/warlord3.png","portraits/orcs/transparent/grunt-2.png"),
#("portraits/orcs/warlord4.png","portraits/orcs/transparent/grunt-2.png"), # see 1.11.3
("portraits/orcs/warlord5.png","portraits/orcs/transparent/grunt-3.png"),
# Changes just before 1.9.0
("flat/grass-r8", "flat/grass6"),
("flat/grass-r7", "flat/grass5"),
("flat/grass-r6", "flat/grass6"),
("flat/grass-r5", "flat/grass5"),
("flat/grass-r4", "flat/grass4"),
("flat/grass-r3", "flat/grass3"),
("flat/grass-r2", "flat/grass2"),
("flat/grass-r1", "flat/grass1"),
("second_value=", "value_second="), # Correct earlier wmllint error
(".stones", ".petrifies"),
("stones=", "petrifies="),
# Changes just before 1.9.1
("[colour_adjust]", "[color_adjust]"),
("[/colour_adjust]", "[/color_adjust]"),
("colour=", "color="),
("colour_lock=", "color_lock="),
# Changes just before 1.9.2
("[removeitem]", "[remove_item]"),
("[/removeitem]", "[/remove_item]"),
# Changes just before 1.11.0
("viewing_side", "side"),
("duration=level", "duration=scenario"), # Note: this may be removed after 1.11.2, so an actual duration=level can be implemented
# Changed before 1.11.3 to incorporate 1.9.0 portraits
("portraits/orcs/warlord2.png","portraits/orcs/transparent/grunt-5.png"),
("portraits/orcs/warlord4.png","portraits/orcs/transparent/grunt-6.png"),
)
def validate_on_pop(tagstack, closer, filename, lineno):
"Validate the stack at the time a new close tag is seen."
(tag, attributes) = tagstack[-1]
ancestors = map(lambda x: x[0], tagstack)
if verbose >= 3:
print '"%s", line %d: closing %s I see %s with %s' % (filename, lineno, closer, tag, attributes)
# Detect a malformation that will cause the game to barf while attempting
# to deserialize an empty unit. The final "and attributes" is a blatant
# hack; some campaigns like to generate entire side declarations with
# macros.
if "scenario" in ancestors and closer == "side" and "type" not in attributes and ("no_leader" not in attributes or attributes["no_leader"] != "yes") and "multiplayer" not in ancestors and attributes:
print '"%s", line %d: [side] without type attribute' % (filename, lineno)
# This assumes that conversion will always happen in units/ files.
if "units" not in filename and closer == "unit" and "race" in attributes:
print '"%s", line %d: [unit] needs hand fixup to [unit_type]' % \
(filename, lineno)
if closer in ["campaign", "race"] and "id" not in attributes:
print '"%s", line %d: %s requires an ID attribute but has none' % \
(filename, lineno, closer)
if closer == "terrain" and attributes.get("heals") in ("true", "false"):
print '"%s", line %d: heals attribute no longer takes a boolean' % \
(filename, lineno)
if closer == "unit" and attributes.get("id") is not None and attributes.get("type") is not None and attributes.get("side") is None and not "side" in ancestors:
print '"%s", line %d: unit declaration without side attribute' % \
(filename, lineno)
if closer == "filter_side":
ancestor = False
if "gold" in ancestors:
ancestor = "gold"
elif "modify_ai" in ancestors:
ancestor = "modify_ai"
if ancestor:
print '"%s", line %d: %s should have an inline SSF instead of using [filter_side]' % \
(filename, lineno, ancestor)
if closer == "effect":
if attributes.get("unit_type") is not None:
print '"%s", line %d: use [effect][filter]type= instead of [effect]unit_type=' % \
(filename, lineno)
if attributes.get("unit_gender") is not None:
print '"%s", line %d: use [effect][filter]gender= instead of [effect]unit_gender=' % \
(filename, lineno)
def within(tag):
"Did the specified tag lead one of our enclosing contexts?"
if type(tag) == type(()): # Can take a list.
for t in tag:
if within(t):
return True
else:
return False
else:
return tag in map(lambda x: x[0], tagstack)
def under(tag):
"Did the specified tag lead the latest context?"
if type(tag) == type(()): # Can take a list.
for t in tag:
if within(t):
return True
else:
return False
elif tagstack:
return tag == tagstack[-1][0]
else:
return False
def standard_unit_filter():
"Are we within the syntactic context of a standard unit filter?"
# It's under("message") rather than within("message") because
# [message] can contain [option] markup with menu item description=
# attributes that should not be altered.
return within(("filter", "filter_second",
"filter_adjacent", "filter_opponent",
"unit_filter", "secondary_unit_filter",
"special_filter", "special_filter_second",
"neighbor_unit_filter",
"recall", "teleport", "kill", "unstone", "store_unit",
"have_unit", "scroll_to_unit", "role",
"hide_unit", "unhide_unit",
"protect_unit", "target", "avoid")) \
or under("message")
# Sanity checking
# Associations for the ability sanity checks.
notepairs = [
("movement_type=undeadspirit", "{SPECIAL_NOTES_SPIRIT}"),
("type=arcane", "{SPECIAL_NOTES_ARCANE}"),
("{ABILITY_HEALS}", "{SPECIAL_NOTES_HEALS}"),
("{ABILITY_EXTRA_HEAL}", "{SPECIAL_NOTES_EXTRA_HEAL}"),
("{ABILITY_UNPOISON}", "{SPECIAL_NOTES_UNPOISON}"),
("{ABILITY_CURES}", "{SPECIAL_NOTES_CURES}"),
("{ABILITY_REGENERATES}", "{SPECIAL_NOTES_REGENERATES}"),
("{ABILITY_STEADFAST}", "{SPECIAL_NOTES_STEADFAST}"),
("{ABILITY_LEADERSHIP_LEVEL_", "{SPECIAL_NOTES_LEADERSHIP}"), # No } deliberately
("{ABILITY_SKIRMISHER}", "{SPECIAL_NOTES_SKIRMISHER}"),
("{ABILITY_ILLUMINATES}", "{SPECIAL_NOTES_ILLUMINATES}"),
("{ABILITY_TELEPORT}", "{SPECIAL_NOTES_TELEPORT}"),
("{ABILITY_AMBUSH}", "{SPECIAL_NOTES_AMBUSH}"),
("{ABILITY_NIGHTSTALK}", "{SPECIAL_NOTES_NIGHTSTALK}"),
("{ABILITY_CONCEALMENT}", "{SPECIAL_NOTES_CONCEALMENT}"),
("{ABILITY_SUBMERGE}", "{SPECIAL_NOTES_SUBMERGE}"),
("{ABILITY_FEEDING}", "{SPECIAL_NOTES_FEEDING}"),
("{WEAPON_SPECIAL_BERSERK}", "{SPECIAL_NOTES_BERSERK}"),
("{WEAPON_SPECIAL_BACKSTAB}", "{SPECIAL_NOTES_BACKSTAB}"),
("{WEAPON_SPECIAL_PLAGUE", "{SPECIAL_NOTES_PLAGUE}"), # No } deliberately
("{WEAPON_SPECIAL_SLOW}", "{SPECIAL_NOTES_SLOW}"),
("{WEAPON_SPECIAL_PETRIFY}", "{SPECIAL_NOTES_PETRIFY}"),
("{WEAPON_SPECIAL_MARKSMAN}", "{SPECIAL_NOTES_MARKSMAN}"),
("{WEAPON_SPECIAL_MAGICAL}", "{SPECIAL_NOTES_MAGICAL}"),
("{WEAPON_SPECIAL_SWARM}", "{SPECIAL_NOTES_SWARM}"),
("{WEAPON_SPECIAL_CHARGE}", "{SPECIAL_NOTES_CHARGE}"),
("{WEAPON_SPECIAL_DRAIN}", "{SPECIAL_NOTES_DRAIN}"),
("{WEAPON_SPECIAL_FIRSTSTRIKE}", "{SPECIAL_NOTES_FIRSTSTRIKE}"),
("{WEAPON_SPECIAL_POISON}", "{SPECIAL_NOTES_POISON}"),
("{WEAPON_SPECIAL_STUN}", "{SPECIAL_NOTES_STUN}"),
]
# This is a list of the standard mainline recruitable usage types. (Two other
# usage types, null and transport, are not normally recruitable.) Additional
# usage classes can be appended with the magic comment, "#wmllint: usagetype".
usage_types = ["scout", "fighter", "mixed fighter", "archer", "healer"]
# This is a list of mainline campaigns, used to convert UMC from
# "data/campaigns" to "data/add-ons" while not clobbering mainline.
mainline = ("An_Orcish_Incursion",
"Dead_Water",
"Delfadors_Memoirs",
"Descent_Into_Darkness",
"Eastern_Invasion",
"Heir_To_The_Throne",
"Legend_of_Wesmere",
"Liberty",
"Northern_Rebirth",
"Sceptre_of_Fire",
"Son_Of_The_Black_Eye",
"The_Hammer_of_Thursagan",
"The_Rise_Of_Wesnoth",
"The_South_Guard",
"tutorial",
"Two_Brothers",
"Under_the_Burning_Suns",
)
# These are accumulated by sanity_check() and examined by consistency_check()
unit_types = []
derived_units = []
usage = {}
sides = []
advances = []
movetypes = []
unit_movetypes = []
races = []
unit_races = []
nextrefs = []
scenario_to_filename = {}
# Attributes that should have translation marks
translatables = re.compile( \
"^abbrev$|" \
"^cannot_use_message$|" \
"^caption$|" \
"^current_player$|" \
"^currently_doing_description$|" \
"^description$|" \
"^description_inactive$|" \
"^editor_name$|" \
"^end_text$|" \
"^difficulty_descriptions$|" \
"^female_name_inactive$|" \
"^female_names$|" \
"^label$|" \
"^male_names$|" \
"^message$|" \
"^name$|" \
"^name_inactive$|" \
"^note$|" \
"^option_description$|" \
"^option_name$|" \
"^order$|" \
"^plural_name$|" \
"^prefix$|" \
"^set_description$|" \
"^source$|" \
"^story$|" \
"^summary$|" \
"^victory_string$|" \
"^defeat_string$|" \
"^gold_carryover_string$|" \
"^notes_string$|" \
"^text$|" \
"^title$|" \
"^title2$|" \
"^tooltip$|" \
"^translator_comment$|" \
"^user_team_name$|" \
"^type_.[a-z]*$|" \
"^range_[a-z]*$")
spellcheck_these = (\
"cannot_use_message=",
"caption=",
"description=",
"description_inactive=",
"end_text=",
"message=",
"note=",
"story=",
"summary=",
"text=",
"title=",
"title2=",
"tooltip=",
"user_team_name=",
)
# Declare a few common English contractions and ejaculations that pyenchant
# inexplicably knows nothing of.
declared_spellings = {"GLOBAL":["I'm", "I've", "I'd", "I'll",
"heh", "ack",
# Fantasy/SF/occult jargon that we need
"aerie",
"aeon",
"aide-de-camp",
"axe",
"ballista",
"bided",
"crafters",
"glaive",
"greatsword",
"hellspawn",
"hurrah",
"morningstar",
"numbskulls",
"overmatched",
"spearman",
"stygian",
"teleport",
"teleportation",
"teleported",
"terraform",
"wildlands",
# game jargon
"melee", "arcane", "day/night", "gameplay",
"hitpoint", "hitpoints", "FFA", "multiplayer",
"playtesting", "respawn", "respawns",
"WML", "HP", "XP", "AI", "ZOC", "YW",
"L0", "L1", "L2", "L3", "MC",
# archaisms
"faugh", "hewn", "leapt", "dreamt", "spilt",
"grandmam", "grandsire", "grandsires",
"scry", "scrying", "scryed", "woodscraft",
"princeling", "wilderlands", "ensorcels",
"unlooked", "naphtha", "naïve",
# Sceptre of Fire gets spelled with -re.
"sceptre",
]}
pango_conversions = (("~", "<b>", "</b>"),
("@", "<span color='green'>", "</span>"),
("#", "<span color='red'>", "</span>"),
("*", "<span size='large'>", "</span>"),
("`", "<span size='small'>", "</span>"),
)
def pangostrip(message):
"Strip Pango markup out of a string."
# This is all known Pango convenience tags
for tag in ("b", "big", "i", "s", "sub", "sup", "small", "tt", "u"):
message = message.replace("<%s>" % tag, "").replace("</%s>" % tag, "")
# Now remove general span tags
message = re.sub("</?span[^>]*>", "", message)
# And Pango specials;
message = re.sub("&[a-z]+;", "", message)
return message
def pangoize(message, filename, line):
"Pango conversion of old-style Wesnoth markup."
if '&' in message:
amper = message.find('&')
if message[amper:amper+1].isspace():
message = message[:amper] + "&" + message[amper+1:]
if re.search("<[0-9]+,[0-9]+,[0-9]+>", message):
print '"%s", line %d: color spec in line requires manual fix.' % (filename, line)
# Hack old-style Wesnoth markup
for (oldstyle, newstart, newend) in pango_conversions:
if oldstyle not in message:
continue
where = message.find(oldstyle)
if message[where - 1] != '"': # Start of string only
continue
if message.strip()[-1] != '"':
print '"%s", line %d: %s highlight at start of multiline string requires manual fix.' % (filename, line, oldstyle)
continue
if '+' in message:
print '"%s", line %d: %s highlight in composite string requires manual fix.' % (filename, line, oldstyle)
continue
# This is the common, simple case we can fix automatically
message = message[:where] + newstart + message[where + 1:]
endq = message.rfind('"')
message = message[:endq] + newend + message[endq:]
# Check for unescaped < and >
if "<" in message or ">" in message:
reduced = pangostrip(message)
if "<" in reduced or ">" in reduced:
if message == reduced: # No pango markup
here = message.find('<')
if message[here:here+4] != "<":
message = message[:here] + "<" + message[here+1:]
here = message.find('>')
if message[here:here+4] != ">":
message = message[:here] + ">" + message[here+1:]
else:
print '"%s", line %d: < or > in pango string requires manual fix.' % (filename, line, oldstyle)
return message
class WmllintIterator(WmlIterator):
"Fold an Emacs-compatible error reporter into WmlIterator."
def printError(self, *misc):
"""Emit an error locator compatible with Emacs compilation mode."""
if not hasattr(self, 'lineno') or self.lineno == -1:
print >>sys.stderr, '"%s":' % self.fname
else:
print >>sys.stderr, '"%s", line %d:' % (self.fname, self.lineno+1),
for item in misc:
print >>sys.stderr, item,
print >>sys.stderr #terminate line
def local_sanity_check(filename, nav, key, prefix, value, comment):
"Sanity checks that don't require file context or globals."
errlead = '"%s", line %d: ' % (filename, nav.lineno+1)
ancestors = nav.ancestors()
in_definition = "#define" in ancestors
in_call = filter(lambda x: x.startswith("{"), ancestors)
ignored = "wmllint: ignore" in nav.text
parent = None
if ancestors:
parent = ancestors[-1]
ancestors = ancestors[:-1]
# Check for things marked translated that aren't strings
if "_" in nav.text and not ignored:
m = re.search(r'[=(]\s*_\s+("?)', nav.text)
if m and not m.group(1):
print errlead + 'translatability mark before non-string'
# Most tags are not allowed with [part]
if "[part]" in ancestors and parent not in ("[part]", "[image]", "[insert_tag]", "[if]", "[then]", "[else]", "[switch]", "[case]", "[variable]", "[deprecated_message]"):
print errlead + '%s not permitted within [part] tag' % parent
# Most tags are not permitted inside [if]
if len(ancestors) >= 2 and ancestors[-1] == "[if]":
if parent not in ("[and]", "[else]", "[frame]", "[have_location]",
"[have_unit]", "[not]", "[or]", "[then]",
"[variable]") and not parent.endswith("_frame]"):
print errlead + 'illegal child of [if]'
# Check for fluky credit parts
if parent == "[entry]":
if key == "email" and " " in value:
print errlead + 'space in email name'
# Check for various things that shouldn't be outside an [ai] tag
if not in_definition and not in_call and not "[ai]" in nav.ancestors() and not ignored:
if key in ("number_of_possible_recruits_to_force_recruit",
"recruitment_ignore_bad_movement",
"recruitment_ignore_bad_combat",
"recruitment_pattern",
"villages_per_scout", "leader_value", "village_value",
"aggression", "caution", "attack_depth", "grouping"):
print errlead + key + " outside [ai] scope"
# Bad [recruit] attribute
if parent in ("[allow_recruit]", "[disallow_recruit]") and key == "recruit":
print errlead + "recruit= should be type="
# Accumulate data to check for missing next scenarios
if parent == '[scenario] or parent == None':
if key == "next_scenario" and value != "null":
nextrefs.append((filename, nav.lineno, value))
if key == 'id':
scenario_to_filename[value] = filename
def global_sanity_check(filename, lines):
"Perform sanity and consistency checks on input files."
# Sanity-check abilities and traits against notes macros.
# Note: This check is disabled on units derived via [base_unit].
# Also, build dictionaries of unit movement types and races
in_unit_type = None
notecheck = True
trait_note = dict(notepairs)
note_trait = dict(map(lambda p: (p[1], p[0]), notepairs))
for nav in WmllintIterator(lines, filename):
if "wmllint: notecheck off" in nav.text:
notecheck = False
continue
elif "wmllint: notecheck on" in nav.text:
notecheck = True
#print "Element = %s, text = %s" % (nav.element, `nav.text`)
if nav.element == "[unit_type]":
unit_race = ""
unit_id = ""
base_unit = ""
traits = []
notes = []
has_special_notes = False
in_unit_type = nav.lineno + 1
hitpoints_specified = False
continue
elif nav.element == "[/unit_type]":
#print '"%s", %d: unit has traits %s and notes %s' \
# % (filename, in_unit_type, traits, notes)
if unit_id and base_unit:
derived_units.append((filename, nav.lineno + 1, unit_id, base_unit))
if unit_id and not base_unit:
missing_notes = []
for trait in traits:
tn = trait_note[trait]
if tn not in notes and tn not in missing_notes:
missing_notes.append(tn)
missing_traits = []
for note in notes:
nt = note_trait[note]
if nt not in traits and nt not in missing_traits:
missing_traits.append(nt)
if (notes or traits) and not has_special_notes:
missing_notes = ["{SPECIAL_NOTES}"] + missing_notes
# If the unit didn't specify hitpoints, there is some wacky
# stuff going on (possibly pseudo-[base_unit] behavior via
# macro generation) so disable some of the consistency checks.
if not hitpoints_specified:
continue
if notecheck and missing_notes:
print '"%s", line %d: unit %s is missing notes +%s' \
% (filename, in_unit_type, unit_id, "+".join(missing_notes))
if missing_traits:
print '"%s", line %d: unit %s is missing traits %s' \
% (filename, in_unit_type, unit_id, "+".join(missing_traits))
if notecheck and not (notes or traits) and has_special_notes:
print '"%s", line %d: unit %s has superfluous {SPECIAL_NOTES}' \
% (filename, in_unit_type, unit_id)
if not "[theme]" in nav.ancestors() and not "[base_unit]" in nav.ancestors() and not unit_race:
print '"%s", line %d: unit %s has no race' \
% (filename, in_unit_type, unit_id)
in_unit_type = None
traits = []
notes = []
unit_id = ""
base_unit = ""
has_special_notes = False
unit_race = None
if '[unit_type]' in nav.ancestors() and not "[filter_attack]" in nav.ancestors():
try:
(key, prefix, value, comment) = parse_attribute(nav.text)
if key == "id":
if value[0] == "_":
value = value[1:].strip()
if not unit_id and not "[base_unit]" in nav.ancestors():
unit_id = value
unit_types.append(unit_id)
if not base_unit and "[base_unit]" in nav.ancestors():
base_unit = value
elif key == "hitpoints":
hitpoints_specified = True
elif key == "usage":
assert(unit_id)