[swift-evolution] [Proposal] Refining Identifier and Operator Symbology
brent at architechies.com
Thu Oct 20 18:02:16 CDT 2016
> On Oct 20, 2016, at 12:25 PM, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> These can be used as identifiers unless they have been defined as an operator somewhere within the project, at which point they switch to being only usable as operators.
Imagine you're the compiler and you've been handed this source file:
let party = 🎉🎂
prefix operator 🎉
You're going to see a keyword "let", an identifier "party", an "=" operator, and then the sequence "🎉🎂". How will you interpret that sequence? There are a few possibilities:
1. A two-character variable named "🎉🎂".
2. A prefix "🎉" operator followed by a one-character variable name "🎂".
3. A two-character operator "🎉🎂" with an operand to follow on the next line.
4. A one-character variable name "🎉" followed by a postfix "🎂" operator.
The operator declaration on the next line will make all of this clear—but we can't understand the next line until we've parsed this line (see #3).
Now, one way around this would be to require all operator declarations to be at the top of the source file. But this would be very strange in Swift, which is otherwise completely insensitive to the order of statements in a declaration scope. And it leads to a strange two-phase behavior when parsing multiple files: You would need to parse each file through the end of its operator declarations before parsing any other code in any of the other files.
I don't think this is something we want to do.
More information about the swift-evolution