Difference between revisions of "User:8680/tmp/AnimationWMLProgressiveStringSquareBracketExpansionSyntax"

From The Battle for Wesnoth Wiki
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Each set of square brackets (‘[’ and ‘]’) contains a comma-separated list — an '''''expansion list''''' — of which each element can be:
 
Each set of square brackets (‘[’ and ‘]’) contains a comma-separated list — an '''''expansion list''''' — of which each element can be:
  
# a '''plain string''' — e.g., “abc” or “123”;
+
* a '''plain string''' — e.g., “abc” or “123”;
# a '''range''', expressed as two radix-10 integers, separated by a tilde — e.g., “1~5”; or
+
* a '''range''', expressed as two radix-10 integers, separated by a tilde — e.g., “1~5”; or
# a '''repetition''', notated as a string and a radix-10 integer, separated by an asterisk — e.g., “a*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”).
 
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”).
Line 15: Line 15:
 
If '''<var>x</var> = <var>y</var>''', then this list has only one element, which is <var>x</var> (and is also <var>y</var>, of course). E.g., “2~2” would becomes “2”.
 
If '''<var>x</var> = <var>y</var>''', then this list has only one element, which is <var>x</var> (and is also <var>y</var>, of course). E.g., “2~2” would becomes “2”.
  
If either <var>x</var> or <var>y</var> 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 <var>x</var> or <var>y</var>) 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”.
+
If either <var>x</var> or <var>y</var> (or both) are padded with '''leading zeros''', then each number in the resultant list will be padded with leading zeros such that it is expressed in at least <var>z</var>+1 digits, where <var>z</var> is the quantity of leading zeros with which one or both endpoints are padded. E.g.,
 +
* “07~11” would become “07,08,09,10,11”,
 +
* “098~100” would become “98,99,100”,
 +
* “0098~100” would become “098,099,100”, and
 +
* “003~1” (or “3~001”) would become “003,002,001”.
 +
 
 +
If both endpoints are padded with leading zeros, they should both be padded with the same quantity of leading zeros.
  
 
==== Repetition expansion ====
 
==== Repetition expansion ====
Line 23: Line 29:
 
==== Square bracket expansion ====
 
==== 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).
+
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 <var>L</var> 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, which is generated as follows:
+
When a progressive string that contains expansion lists is processed to expand its expansion lists, it is transformed into a comma-separated list with <var>L</var> elements.
  
For each integer <var>n</var> from 1 to <var>L</var>, where <var>L</var> is the length in elements of each expansion list (after range and repetition expansion):
+
For each integer <var>n</var> from 1 to <var>L</var>, the <var>n</var>-th element of this list shall be a copy of the progressive string, with each expansion list it contains replaced with that expansion list’s <var>n</var>-th element (after range and repetition expansion).
:If
 

Latest revision as of 23:56, 14 February 2014

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

  • a plain string — e.g., “abc” or “123”;
  • a range, expressed as two radix-10 integers, separated by a tilde — e.g., “1~5”; or
  • 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 (or both) are padded with leading zeros, then each number in the resultant list will be padded with leading zeros such that it is expressed in at least z+1 digits, where z is the quantity of leading zeros with which one or both endpoints are padded. E.g.,

  • “07~11” would become “07,08,09,10,11”,
  • “098~100” would become “98,99,100”,
  • “0098~100” would become “098,099,100”, and
  • “003~1” (or “3~001”) would become “003,002,001”.

If both endpoints are padded with leading zeros, they should both be padded with the same quantity of leading zeros.

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 replaced with that expansion list’s n-th element (after range and repetition expansion).

This page was last edited on 14 February 2014, at 23:56.