auto-recognize the people in the NAMED_*UNIT macros

If we have a regex match for the macro, we parse it and see if it meets key tests:

* There are at least 7 arguments parsed (NAMED_UNIT can have extra WML).
* The original regex could also match UMC macros, like "Attack of the Western Cavalry"'s NAMED_SHIP_UNIT. To make sure that such macros are following the format of the core macros, we check that the side, x, and y fields are numbers, or variables/macros consistent with those fields.
* Also make sure that the id field isn't blank. Not only would adding an empty id to the list of present characters be pointless, that list is added to spellings, and zero-length entries crash the spell-check.

If all those tests are passed, we append the id argument to the list of the present.

I also tweak the wording in the intro about the "wmllint: recognize" magic comment to reflect that wmllint is now recognizing ids in some macros.
This commit is contained in:
Groggy Dice 2013-12-17 04:27:43 -05:00
parent c33b4c47ad
commit 6dde83c3ac

View file

@ -65,8 +65,8 @@
# 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 macros
# and wmllint cannot recognize it.
# also be useful if you have wrapped unit-creation or recall markup in
# non-core macros and wmllint cannot recognize it.
#
# For macros used in multiple scenarios to field characters, you can tell
# wmllint to recognize them with another magic comment:
@ -1448,6 +1448,15 @@ def global_sanity_check(filename, lines):
(args, brack, paren) = parse_macroref(0, leadmac.string)
if len(args) == 7:
lines[i] = lines[i].replace('{LOYAL_UNIT', '{NAMED_LOYAL_UNIT', 1)
# Auto-recognize the people in the {NAMED_*UNIT} macros.
if re.match(r'NAMED_[A-Z_]*UNIT$', macname):
(args, brack, paren) = parse_macroref(0, leadmac.string)
if len(args) >= 7 and \
re.match(r'([0-9]+|[^\s]*\$[^\s]*side[^\s]*|{[^\s]*SIDE[^\s]*})$', args[1]) and \
re.match(r'([0-9]+|[^\s]*\$[^\s]*x[^\s]*|{[^\s]*X[^\s]*})$', args[3]) and \
re.match(r'([0-9]+|[^\s]*\$[^\s]*y[^\s]*|{[^\s]*Y[^\s]*})$', args[4]) and \
len(args[5]) > 0:
present.append(args[5])
# Recognize macro pairings from "wmllint: who" magic
# comments.
for mac in whopairs.keys():