Compartir a través de


Ranges

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

Range expressions are a shorthand way to express alternatives that include all the characters in a range.

The range expression consists of a quoted character that represents the lower bound of the range, followed by the range operator (..), followed by a quoted character that represents the upper bound of the range.

Range literals can only be used with literals that are one character in length, and the Unicode value of the lower-range character is less than that of the upper-range character.

Examples

The following are some examples of the range operator. They are all taken from the grammar that defines MGrammar itself.

Simple Range

The following code shows several examples of the range operator.

        token Digit     = '0'..'9';
        token UpperCase = 'A'..'Z';
        token LowerCase = 'a'..'z';

Compound Ranges

The range operator can be used with the alternation operator (|) to specify disjoint ranges of characters. The following code shows several examples of this.

        token HexDigit = Digit | 'a'..'f' | 'A'..'F';
        token Letter   = 'A'..'Z' | 'a'..'z' |'_';