-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpreter allows arbitrary commands to be executed via the comment #1504
Comments
Though I think it might be useful to even allow the |
So here's a question I've been thinking about, which seems related to this:
or whatever? I assume the reasoning it's required in the case where options actually need to be specified is to make it less ambiguous if a comment at the start is for
That would make it unambiguous, it'd fit in with other pragmas better, and it'd mean that that extra line wouldn't be required when nothing needs to be specified. I ask because ... coming from using shebangs in other languages like python, I don't know of any of them that require an extra configuration line like that, so it stands out as really weird to me. |
This is really a hack for stack and not required by language per se. If not using stack the shebang would be a standard In the current form it is a real valid stack command which can be run on the command line with the file name added at the end. A pragma like syntax is trivial to support but the real question is what should be the content of the pragma syntax? Will it be a valid stack command? If not then in what way will it be different than a command? We can omit the command and assume it to be |
I agree the current syntax is a bit weird and non standard. A pragma like syntax is already known and learnt and looks better to me. Also see #1394 where a pragma like syntax was suggested earlier and was countered by @borsboom . Another point is that since it is not a ghc recognised pragma, we will have to pass something like |
I'm not really clear on how a pragma would be more confusing in that regard than the current method. If anything it could probably be worded to be less confusing with the right "word" in As to GHC being noisy about it, maybe the GHC people could be argued into not warning about a pragma that doesn't make sense for them to handle and obviously isn't a typo of one they should. |
Let me try a concrete proposal so that it is easier to debate and request concrete feedback from others. Let's consider replacing the current syntax with a pragma as follows:
alternately when the line gets too long:
Now what would be valid content inside the pragma? To keep it consistent and simpler to understand, we can have a rule that if you replace RUNSTACK with So the equivalent command line corresponding to the pragma above would be: The keyword RUNSTACK indicates that this is a pragma for running the file using stack and the naming is consistent with other ways to run a script like Requesting feedback on the above from people involved in the previous discussion about this i.e. @ndmitchell , @borsboom , @mgsloan . |
Stack interpreter comment annotation allows arbitrary commands to be written and executed when the file is run. It can lead to confusing and surprising behavior if mistakes are made in writing a proper comment. This change restricts the interpreter mode commands to runghc and runhaskell. This change moves add-commands to a separate function. Closes commercialhaskell#1504
To me the proposal there looks nice. I'd be interested to see what the devs think about it. (only comment I'd have is I'm not sure if the multi-line thing is allowed syntax for haskell pragmas, if not another option would be to allow multiple pragmas and just concatenate them all together) |
I checked it before proposing :-) It seems to pass through GHC. There is a corner case though, if the last line (i.e. |
Hmm, I don't see any benefit to using pragma syntax. The only thing I can think of is that it's normal for |
The argument in favor of it is consistency with the widely known and accepted pragma syntax. For example, just by looking at it someone not even knowing about the stack comment syntax can perhaps easily tell that it is some directive rather than a simple innocuous comment. If we agree that this is the right thing, effort is not a problem. We already support the I have not investigated the GHC warning further but maybe it can be solved by passing an extra flag like I like it only for the consistency argument. On the other hand, the good thing about the current syntax is that its a plain stack command which is a relatively simple fact to know. Also, it is more powerful, for example by using a |
It doesn't seem consistent to me, because pragmas are for the compiler. To me, |
For example:
It can confuse and surprise if one writes a wrong comment.
I have a fix which restricts the commands to
runhaskell
andrunghc
in the interpreter mode.The text was updated successfully, but these errors were encountered: