On 18 August 2016 at 20:51, Sven Panne <[email protected]> wrote: > 2016-08-17 16:37 GMT+02:00 Harendra Kumar <[email protected]>: > >> ghc accepts a flag and its argument as a single quoted or escaped >> argument as well. For example all of the following are equivalent: >> >> ghc -package foo >> ghc "-package foo" >> ghc -package\ foo >> >> Is this by design or accidental? >> > > I would call this a bug, probably some missing quoting somewhere: Most > commands I know don't do splitting on the arguments for themselves. Just > try e.g. > > gcc "-v -v" >
Initially I too thought the same but then I did some more testing and it turned out that the way ghc does not really parse it exactly in the same way as independent unquoted arguments. It only parses a flag which takes an argument. For example: ghc "-package foo" -- parses foo as an argument to the -package flag ghc "-package foo -v" -- is not the same as "-package foo" and "-v" arguments passed independently, it is "foo -v" as the argument to "-package" So it essentially allows packing a flag and its argument together. Which provides a nice way to pass flags and their values as a single unit. This may be accidental to begin with but I liked this just because it makes passing opaque flags combined with arguments from a wrapper program like runghc much more convenient. I cannot think of any downside of this behavior unless someone points out otherwise. > >> This has a nice side effect to make passing ghc arguments via rughc >> simple. For example runghc "-package foo" or runghc -package\ foo will pass >> "-package foo" to ghc. The alternative and documented way to achieve the >> same effect is runghc -package --ghc-arg=foo which is not that convenient. >> >> My question is - can we rely on this way of parsing? If it is not by >> design, does it make sense to legalize and therefore document this? >> > > And my question is: Can we fix this bug? :-D If this is not considered a > bug, we should be very explicit about this deviation from standard behavior > in the documentation, including the reasons for it. > As I explained above, I would prefer to keep this bug :-) and document it especially for runghc as a better alternative to --ghc-arg=foo . So instead of saying: runghc -package --ghc-arg=text -package --ghc-arg=turtle hello.hs We can just say: runghc "-package text" "-package turtle" hello.hs -harendra
_______________________________________________ ghc-devs mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
