This required care to:
* not add ids inside [not] tags
* remove items from dictionary not just when unstored, but when
clear_variable is used
* handle comma-separated values
Sigh. Probably should re-write the .plain file parser to first remove
all commands, keeping the meta-information in a separate class. Then
parse the result (which should be much simpler) and consult the
meta-information where necessary (text-domain for strings, source files
and line numbers for tokens).
The last commit fixed one issue but introduced yet another. Now both
should work. Need to investigate if parsing the .plain files really is
necessary, would make things much easier if there was no need for it.
For example defined strings with empty lines would not work. The problem
was a direct check for newlines which failed if there were chr(254)
commands on the same line.
I actually thought this was already checked by the "unknown 'xx' referred to
by id" warning. Probably because many more [message]s used to use id= and
role= rather than speaker=.
As a side effect, this new error will force designers to use my 'who' and
'whofield' magic comments!
I am responsible for wmlscope suddenly giving macro mismatch errors, as was
pointed out on IRC. The tell is that in each of these errors, the last field
is interpreted as a stringliteral.
An argument that starts and ends with a quote is interpreted as a stringliteral.
But under previous code, that couldn't happen: quote characters toggled the
instring status on and off, but weren't added to arg, so no arg contained any
quotes. I didn't like the fact that this stripped the quotes out of translatable
strings, so I changed the code to include quotes in arg and strip them out if
they began and ended the arg. Unfortunately, while I stripped out quotes when
arg was terminated by a space, I didn't think it was necessary when the right
bracket terminated the arg. It was.
The tags are now tested directly, rather than as a parent of a key. The old
test was probably not missing tags like the test for illegal child of [if]
did, because [part] could be anywhere in ancestors. Anyway, [part] rarely
contains other tags.
Previously, only lines that parse_attribute could process got passed to
local_sanity_check. So tags survived as ancestors of attribute lines, but
the lines with the tags themselves got discarded. Hence, the "illegal child
of [if]" error was actually triggered by attributes, and the line number
referred to that line rather than the child tag.
While working on [aspect] and [facet] (which originally preceded this commit),
I changed the TypeError exception to pass all lines to local_sanity_check. This
allows for a direct test of the child tags. It turns out many child tags were
not tested because all the attributes were nested deeper inside other tags,
so that the child tag was not the parent of any attribute.
Two core macros failed the new test with the tags [filter_second] and
[filter_second_attack]. This pointed up the fact that these were not in the
list of valid child tags.
It also turns out that tags inside #ifdefs didn't fit the original test,
because "#ifdef" was considered an ancestor, interrupting the link between
"[if]" and the child tag.
Previously, the string only needed to match part of the macro. However, this
left too much room for unintended matches. This change is also quicker for
wmllint to process.
After a line ending in a '+', the C++ parser ignores any number of newlines,
wmlparser2 only ignored a single one. This case did not appear in mainline.
This moves the after the fall schedule into core to grant that the
debian package wesnoth-editor does not depend on wesnoth-utbs.
Also, the images now life in their own subdirectories.
Wmllint has been updated to take care about the changed paths.
Although we can now auto-recognize characters in the core NAMED_*UNIT macros,
campaigns may have their own recruit/recall macros. This comment will tell
wmllint which field contains the macro's id.
The basic format is 'wmllint: whofield <macro> <num>'. This commit sets up the
dictionary, the next commit will actually parse the macros. It will explain
more details about how to use this magic comment in wmllint's introduction.
Although this is not a core macro (yet - I've been meaning to ask why Wesnoth doesn't have core recall macros), it is used in many UMC projects in a consistent format, making it a de-facto standard. Test that the macro has only one field, to make sure it isn't deviating from the format.
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.
As it was, the code was excluding all quotes from arg, even in translatable strings. Although this did not break any code that uses the args, I don't care for that behavior.
During testing, I found that spaces inside quotes were preserved by the "instring" code, but not spaces inside naked parentheses. For example, "(Elvish Rider)" would be turned into "ElvishRider". This fix keeps interior whitespace from being discarded; the problem of leading and trailing whitespace is dealt with by stripping the arg before appending it to args.
This will keep non-core usage types from being described as a "non-standard usage class" in recruitment error messages. These error messages will only be triggered if there is a mismatch between recruits and recruitment patterns, so this magic comment is low-priority.
It was suggested that wmllint could auto-detect new usage values in unit files, and automatically append them to the list of recognized usage types. This was rejected because of the possibility of adding misspelled or mistaken usage types.
When recruitment patterns include bogus usage classes, it will trigger a message during the consistency check. However, this check won't tell you whether your problem is with the usage classes or the recruits. For example, if you get a message that "no light fighter units are recruitable", your first thought might be that you didn't include a light fighter unit in the recruit list. The message doesn't clue you in directly that the light fighter simply doesn't exist in mainline.
Now a clause will be added to the message when non-mainline recruitment classes are involved, alerting designers when bogus usage classes are involved, but mild enough that it hopefully won't scare away authors legitimately seeking to use custom classes.
This replaces the old usage check. The next commit will add a magic comment for appending custom usage types.