Share via


interleave

[This is prerelease documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This keyword specifies the characters that are ignored when parsing the input.

An interleave rule must contain a name and one or more productions. Each production can consist of multiple terms.

interleave RuleName    =      Productions ;

Productions : 
    Production  OR 
    Productions | Production

Production :
    Terms

Terms :
    Term OR
    Terms Term

Term :
    TextLiteral OR
    CharacterRange OR
    Character + Kleene Operator OR
    Rule Reference OR
    In-line rules OR
    "any"

Rule Name

RuleName is any valid “M” identifier.

Productions

A rule contains one or more productions, separated by the "or" (|) operator. Each production consists of a sequence of terms.

Terms

A term can consist of one of the following:

  • A text literal.

  • A range of characters.

  • An in-line rule, such as "A" ("," "A")*.

  • Characters with Kleene operators applied.

  • A reference to another rule. Note that multiple references to syntax rules are not allowed in a production.

  • The literal any, which is a wildcard that matches any text value of length 1.

These terms can be combined into expressions using the difference, intersection, and inverse set operators.

Remarks

Use of whitespace characters is a common method for making text more readable, as well as providing separators between parts of a language. Common whitespace characters include spaces, tabs, and returns.

Example

The following code recognizes character strings of the form "Hello {, Hello}*", such as the string "Hello" followed by 0 or more occurrences of the string ", Hello".

The interleave keyword enables the input string to be spread across multiple lines.

Try typing in valid instances of the string, with returns and spaces interspersed, and note that these strings are valid.

module HelloWorld 
{
    language HelloWorld 
    {
        syntax Main      = HelloList;
        syntax HelloList = Hello
                         | HelloList "," Hello;
        syntax Hello     = "Hello";
         // Ignore whitespace
        syntax LF    = "\u000A";
        syntax CR    = "\u000D";
        syntax Space = "\u0020";
        interleave Whitespace = LF | CR | Space;                 
    }
}

Fill out a survey about this topic for Microsoft.