[swift-evolution] [Discussion]: Renaming #line, the line control statement

Adrian Prantl aprantl at apple.com
Thu Feb 4 12:38:00 CST 2016


> On Feb 4, 2016, at 9:31 AM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Feb 3, 2016, at 7:29 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>> line-control-statement → #line­
>>> line-control-statement → #line­line-number­file-name­
>>> line-number → A decimal integer greater than zero
>>> file-name → static-string-literal­
>>> 
>>> The accepted implementation of SE-0028 disambiguates the two by requiring #line (the control statement) to appear at the first column for the time being. This is a stop-gap solution best remedied by renaming #line. 
>>> 
>>> Chris Lattner writes, "The core team isn’t thrilled with the magic “first token on a line” whitespace behavior that #line will be getting, and would like someone to start a discussion about renaming the old #line directive to something more specific and tailored to its purpose.   Once that name and syntax is settled, we can rename the directive and remove the whitespace rule."
>>> 
>>> I'd recommend #setline or #linenumber. Starting this thread to solicit other suggestions.
>> 
>> I don't love the way the current format has two unlabeled parameters in an arbitrary order. Maybe something more like this?
>> 
>> 	#reset line=50, file="foo.swift"
>> 
>> (I have a soft preference for "reset" over "set" because these are things the compiler changes automatically, but that might be a silly reason.)
>> 
>> Perhaps this could even let you set any combination of the #whatever parameters, so if, for instance, you were writing a parser generator, you could set #function to the name of the rule a particular piece of code came from.
> 
> Using something like this as the grammar structure makes sense to me, but I’d suggest something more specific (and longer) for this, perhaps:
> 
> #setsyntacticsourcelocation
> 
> or something. :-)

Is compatibility with the C preprocessor and other preprocessors that emit #line directives a non-goal for Swift?
I guess we probably don’t want to encourage (ab-)use of the C preprocessor and one could easily translate #line directives to Swift’s syntax by preprocessing the preprocessor output with sed, but I’m curious.

-- adrian


More information about the swift-evolution mailing list