Note that types and proper patterns are unified with one non-terminal operator, called Pattern, reflecting that types are subset of patterns.
Composed Patterns
Pattern ::= ([|Expression|])? Pattern | ([|Expression|])? Pattern[1]
Pattern[1] ::= Pattern[1] & Pattern[2]
Pattern[2] ::= Pattern[2] + Pattern[3]
Count Patterns
Pattern[3] ::= Pattern[4] *
Pattern[3] ::= Pattern[4] +
Pattern[3] ::= Pattern[4] #?
Pattern[3] ::= Pattern[4] # PatternCountValue
Pattern[3] ::= Pattern[4] # PatternCountValue .. PatternCountValue?
Pattern[3] ::= Pattern[4] #.. PatternCountValue
PatternCountValue ::= PrimaryExpression
From (Decoding) Pattern
Pattern[3] ::= Pattern[4] from Reference
Pattern[4] ::= Pattern[5] Constraint
Constraint ::= where Expression
Capture Patterns
Pattern[5] ::= Identifier : Pattern[6]
Pattern[5] ::= var Identifier
PrimaryPattern ::= Pattern[6]
Pattern[6] ::= ! Pattern[6]
Nullable or Optional Patterns
Pattern[6] ::= Pattern[7] ?
Pattern[6] ::= optional ([|Expression|])? Pattern[7]
Note: in the context of a sequential pattern, this operator denotes 0 or 1 repetitions. In the context of a singleton pattern, it denotes nullable.
Parenthesized Patterns
Pattern[7] ::= ( Pattern )
Pattern[7] ::= PrimaryPattern(( Pattern ( , Pattern )* )? )
Reference Patterns
Pattern[7] ::= ReferencePattern
ReferencePattern ::= ReferencePatternIdentifier GenericArguments? TypeArguments?
TypeArguments ::= [ ( Expression ( , Expression )* )? ]
ReferencePatternWithoutArguments ::= ReferencePatternIdentifier GenericArguments?
ReferencePatternIdentifier ::= QualifiedIdentifier | PredefinedTypeIdentifier
PredefinedTypeIdentifier ::=
byte | sbyte | short | ushort | int | uint | long | ulong | float | double | decimal | guid | bool | char | string | binary | any | any aspect | any endpoint | any message | any type | array | set | map | | json | xml | treedata | void
Pattern[7] ::= $ PrimaryExpression
Pattern[7] ::= Literal
Pattern[7] ::= regex BlockLiteral
Range Patterns
Pattern[7] ::= $ PrimaryExpression .. PrimaryExpression
Pattern[7] ::= Literal .. Literal
Membership Patterns
Pattern[7] ::= in Expression
Compound Patterns
Pattern[7] ::= (\\ | \)? ReferencePattern FieldPatterns? ((\\ | \) ReferencePattern FieldPatterns?)* )
FieldPatterns ::= { (FieldPattern ( , FieldPattern )* )? }
FieldPattern ::= (Identifier | exception) is Pattern | Identifier == Expression | Expression
Array Patterns
Pattern[7] ::= [ SequentialPattern? ]
SequentialPattern::= Pattern ( , Pattern )* ( , WildcardPattern? )?
WildcardPattern ::= ... ( Identifier )?
Map Patterns
Pattern[7] ::= { ( EntryPattern ( , EntryPattern )* ( , WildcardPattern? )? )? }
EntryPattern ::= Expression -> Pattern
Pattern[7] ::= { SequentialPattern? }
Enum Patterns
Pattern[7] ::= ( enum | flags ) EnumBase? { (EnumField ( , EnumField )* )? ,? }
EnumBase ::= ReferencePatternWithoutArguments
EnumField ::= Identifier ( = Expression)? Aspects?
Reference Patterns with Capture
Pattern[7] ::= ReferencePatternWithCapture
ReferencePatternWithCapture ::= (Identifier:)? ReferencePattern
Share with your friends: |