User:8680/tmp/AnimationWMLProgressiveStringSquareBracketExpansionSyntax

From The Battle for Wesnoth Wiki
Revision as of 22:51, 11 February 2014 by 8680 (talk | contribs)

Each set of square brackets (‘[’ and ‘]’) contains a comma-separated list — an expansion list — of which each element can be:

  1. a plain string — e.g., “abc” or “123”;
  2. a range, expressed as two radix-10 integers, separated by a tilde — e.g., “1~5”; or
  3. a repetition, notated as a string and a radix-10 integer, separated by an asterisk — e.g., “a*3”.

Ranges can not only be from a lesser number to a greater number (e.g., “1~5”), but can also be backward — from a greater number to a lesser number (e.g., “5~1”).

Range expansion

Each range x~y is expanded within its expansion list to a comma-separated list of radix-10 integers (which are plain strings), starting from the first endpoint x and ending at the second endpoint y.

If x < y, then the numbers in this list increase by increments of 1; if x > y, then the numbers in this list decrease by decrements of 1. E.g., “1~3” would become “1,2,3”, and “3~1” would become “3,2,1”.

If x = y, then this list has only one element, which is x (and is also y, of course). E.g., “2~2” would becomes “2”.

If either x or y are padded with leading zeros, then each number in the resultant list will be padded with leading zeros such that it is expressed in as many digits as the endpoint (either x or y) that is padded with the most leading zeros. E.g., “07~11” would become “07,08,09,10,11”, and “003~1” (or “3~001”) would become “003,002,001”.

Repetition expansion

Each repetition s*n is expanded within its expansion list to a comma-separated list with n elements, each of which is the string s. E.g., “abc*3” would become “abc,abc,abc”.

Square bracket expansion

A single progressive string value may contain multiple square-bracketed expansion lists, which must all be of the same length in elements (after range and repetition expansion). This length shall be referred to as L for the remainder of this section.

When a progressive string that contains expansion lists is processed to expand its expansion lists, it is transformed into a comma-separated list with L elements.

For each integer n from 1 to L, the n-th element of this list shall be a copy of the progressive string, with each expansion list it contains (after range and repetition expansion) replaced with that expansion list’s n-th element.