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
Warning for unused quoted string id #6715
Comments
Comment author: @gasche I don't agree with this proposal. Non-trivial delimiters are useful for other things than ppx expansions. They allow to embed strings without having to escape things, which is very useful if you want to represent, say, a program, in a readable way. Escaping can only be avoided if arbitrary delimiters are allowed in normal usage (otherwise the use of eg. "|}" in the program being quoted would prevent from using quoted string literals). This is in particular true when the string represents OCaml code (which may itself contain a quoted string representing OCaml code). Furthermore, there already exists a way to force extensions to handle a string, and have a failure otherwise: extension points. Instead of trying to assign a different semantics to {sql|...|sql} (which I think is a bad idea for the same general reasons that changing the semantics of valid OCaml code by preprocessing is a bad idea), you should use [%sql{| ... |}]. This has the property that users will get an error if no extension preprocesses it. |
Comment author: @lpw25
This is indeed the recommended way to provide such extensions. It also has the benefit of supporting nested quotations.
|
Comment author: @alainfrisch I agree with the two previous notes. Moreover, even if a ppx processor is triggered by a specific delimiter of quoted strings (which is not recommended), forgetting to apply the ppx won't go unnoticed for long (unless the expansion has type string). |
Comment author: @hcarty Thank you all for the clarifications. I was under the impression that one of the intended use cases for quoted strings was a replacement for camlp4 quotations. To Alan's point, the expansion in some cases would have type string. Think of a replacement for Gerd's xstrp4. The [%extension{|content|}] form works well enough for this though. This entry can be closed. |
Comment author: @lpw25
There was some discussion on the wg-camlp4 mailing list about providing a direct replacement for camlp4 quotations with a syntax like {%foo| ... |}. But in the end it was decided that using [%foo ... ] in combination with a new string syntax {| ... |} was a better approach. |
Original bug ID: 6715
Reporter: @hcarty
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:37:14Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 4.02.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @hcarty
Bug description
4.02 brought quoted strings in the form {id||id}. It would be nice if there were a way to enable warnings when a quoted string with an id <> "" is not handled by a ppx extension.
Quoted strings provide a ppx-friendly way to replace some uses of camlp4's quotations. The quoted string approach unfortunately lacks a way to warn users when the appropriate ppx has not been applied.
An example of this may be a {sql|select ${some_ocaml_expression} from bar|sql} extension which would perform context-sensitive string interpolation.
Additional information
The arguments for and against such a warning may be similar to those for and against warning on unused annotations.
The text was updated successfully, but these errors were encountered: