-
Notifications
You must be signed in to change notification settings - Fork 90
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
show doesn't have a handler for Uchar.t #174
Comments
(BTW, what's a reasonable temporary workaround?) |
In general, if there's a type without an existing deriver you can create a type alias and define your own deriver. In the case of type uc = Uchar.t
let pp_uc pp uc = ...
type t = { u : uc } [@@deriving show] |
Please submit a PR for |
I can submit a PR for |
|
Or maybe |
That latter suggestion isn't far from what @Drup suggested, though figuring out what's printable given only the tools in the stdlib isn't easy, so it might need to default to the latter. |
|
You can conservatively stick to ASCII. 0x20..0x7E? |
Sorry, can you expand on that? |
@hcarty btw, in your example: let pp_uc pp uc = ... I am guessing the |
I mean, convert it to |
My current prototype is: let pp_uchar f uc =
let ui = Uchar.to_int uc in
if ui < 128
then Format.fprintf f "(Uchar.of_char '%s')" (Char.escaped (Uchar.to_char uc))
else Format.fprintf f "(Uchar.of_int 0x%04x)" ui |
You need to skip |
Why? Tab is better expressed as |
(I can see suggesting that things other than |
Oh sorry, I missed |
One suggestion for an OCaml Uchar.t direct syntax that’s evolved on the discord channel:
(for direct entry of Unicode chars in source) and
(for entry of chars by their hex codepoint.) It’s gross, but finding something less gross seems hard… |
This convention could be implemented in a printer as: let pp_uchar f uc =
let ui = Uchar.to_int uc in
if (ui > 31 && ui < 127) || (ui = 9) || (ui = 10) || (ui = 13)
then Format.fprintf f "\\u'%s'" (Char.escaped (Uchar.to_char uc))
else Format.fprintf f "\\u{%x}" ui |
Okay, so I started looking at implementing this in ppx_deriving.show and realized that I really should be proposing implementing it in Printf so it could be standard across OCaml, but for the moment, I'm not sure I entirely understand the code in |
Yes, I believe that is the right place to implement support for |
One question is, should I start there, or should I propose something for Printf or even the lexer? |
Why not both? The stdlib/compiler changes will likely take a lot of time. |
I suppose the "why not both" is that I've gotten gunshy about proposing stdlib and compiler changes, but yah, I suppose I should start somewhere. Is the proposed syntax tasteful enough to you? |
@pmetzger I like the syntax. |
show doesn't have a built-in handler for Uchar.t, which makes it messy to try to derive a show function for something containing a Uchar.t.
The text was updated successfully, but these errors were encountered: