[swift-evolution] [Proposal] Refining Identifier and Operator Symbology
amartini at apple.com
Wed Oct 19 12:12:41 CDT 2016
> Dots in operators
> The current requirements for dots in operator names are:
> If an operator doesn’t begin with a dot, it can’t contain a dot elsewhere.
> This proposal changes the rule to:
> Dots may only appear in operators in runs of two or more.
> Under the revised rule, ..< and ... are allowed, but <.< is not. We also reserve the .. operator, permitting the compiler to use .. for a "method cascade" syntax in the future, as supported by Dart <http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html>.
> Motivations for incorporating the two-dot rule are:
> It helps avoid future lexical complications arising from lone .s.
> It's a conservative approach, erring towards overly restrictive. Dropping the rule in future (thereby allowing single dots) may be possible.
> It doesn't require special cases for existing infix dot operators in the standard library, ... (closed range) and ..< (half-open range). It also leaves the door open for the standard library to add analogous half-open and fully-open range operators <.. and <..<.
> If we fail to adopt this rule now, then future backward-compatibility requirements will preclude the introduction of some potentially useful language enhancements.
> <https://github.com/jtbandes/swift-evolution/blob/unicode-id-op/proposals/NNNN-refining-identifier-and-operator-symbology.md#grammar-changes-1>Grammar changes
> operator → operator-head operator-characters[opt]
> operator-head → ! % & * + - / < = > ? ^ | ~
> operator-head → operator-dot operator-dots
> operator-character → operator-head
> operator-characters → operator-character operator-character[opt]
> operator-dot → .
> operator-dots → operator-dot operator-dots[opt]
> <https://github.com/jtbandes/swift-evolution/blob/unicode-id-op/proposals/NNNN-refining-identifier-and-operator-symbology.md#emoji>I think there's a mismatch between the English and grammar. For example, is +..+ allowed or not?
The English rule does allow +..+ because its dots appear in a run of two.
The grammar allows a run of one or more dots as an operator head, but never allows dots as characters appearing in the middle of an operator, regardless of how many dots appear next to each other. The grammar wouldn't allow +..+ because the dots don't come at the beginning.
Here's an alternate version of the grammar that matches the "two or more" rule. Because we no longer distinguish between which characters are allowed as the first character of an operator vs a character inside, there's no longer a need for a separate operator-head.
operator --> operator-character operator-OPT
operator-character --> ! % & * + - / < = > ? ^ | ~
operator-character --> operator-dots
operator-dots --> .. operator-additional-dots-OPT
operator-additional-dots --> . operator-additional-dots-OPT
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution