Make //+build and other similar tags not be a comment
#4200
Replies: 6 comments 12 replies
-
|
If the |
Beta Was this translation helpful? Give feedback.
-
|
i propose a new distinct token such as /# for such options. this should make it easy for editors and it will prevent confusion by having similar syntax do other things. |
Beta Was this translation helpful? Give feedback.
-
|
I did some experiments: https://github.com/odin-lang/Odin/compare/master...karl-zylinski:Odin:file-tags-without-comments?expand=1 In that branch I have made it so that It's quite simple changes, it mostly adds a new token Just having |
Beta Was this translation helpful? Give feedback.
-
|
I made a draft PR with my changes: #4203 |
Beta Was this translation helpful? Give feedback.
-
|
Interesting thoughts. Shell scripting has this same situation with shebangs.
|
Beta Was this translation helpful? Give feedback.
-
|
This has been fixed since #4203 got merged! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The problem
Currently you can add tags at the top of files, before the package line. Such as:
This tag makes the file only build on the platforms listed.
However, the tag is within a comment. This has several problems:
//+build darwin, linuxthink its just an informational comment.//+build darwin, linuxthink the actual tag should be+build darwin, linuxbut it has been disabled by commenting it out.There are additional tags such as
//+privateand//+no-instrumentationthat have the same issues.My suggested solutuion
Drop the comment:
This has problems because the syntax is incompatible with the rest of the language.
Therefore I suggest that anything that goes before the
packageline has syntax rules of its own. Almost like a mini language.This might sound bad, but in a sense we already have this:
This build-tag-in-a-comment is only valid before the package line, but it just doesn't do anything if it's anywhere else in the file. So the current solution is like a mini-language that is hidden in comments, but it doesn't affect the rest of the file because it's in a comment.
So my suggestion is to explicitly introduce separate syntax rules for things above the package line. It is of course not a perfect solution either. But everything here is a compromise, and I think it's a lot better than the current solution.
Migration
It's easy to migrate to the new style: search and replace all of core and base for the
//+buildtags and the other tags and replace them with variants without the//in front.During a transition period both can be supported with a warning saying that you should remove the
//.Update
I did some experiments, they can be seen in this draft PR: #4203
Beta Was this translation helpful? Give feedback.
All reactions