[swift-evolution] [Proposal] Refining Identifier and Operator Symbology

Brent Royal-Gordon 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.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list