Skip to content
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

Strformat symbol binding #10927

Merged
merged 8 commits into from
Apr 5, 2019
Merged

Conversation

krux02
Copy link
Contributor

@krux02 krux02 commented Mar 29, 2019

  • strformat.format is renamed to strformat.formatValue, so it does not clash with strutils.format.
  • The (in my opinion complicated and weird logic) in the callFormat templates is removed entirely. formatValue has to follow the interface formatValue*(value: T; specifier: string; res: var string). Hacks to support alternative interfaces are removed.
  • Libraries can overload formatValue to enable custom types within to be used in the & macro.
  • Libraries have full control over the meaning of the specifier string for their own types.
  • The changes above enable an implementation for the nim_glm types to be used in the & macro.
  • fixes strformat doesn't work properly inside generics #7632
  • the macro & is moved below the definition of formatValue, so that bindSym gets them all. Sorry that makes the diff harder to read, but it is important.

breaking change:

Custom types now need to overload formatValue explicity. It would be possible to provide a generic formatValue that is based on $, but I decided against it. Most importantly, when the generic formatValue does not exist, there is a really nice error message that tells the developer that there is a missing formatValue that should be implemented. I also did it, because it is not clear to me what to do with the specifier argument.

@krux02
Copy link
Contributor Author

krux02 commented Apr 3, 2019

The test suid did already pass before I did a minor change.

@krux02 krux02 closed this Apr 3, 2019
@krux02 krux02 reopened this Apr 3, 2019
@Araq Araq merged commit 3a5a0f6 into nim-lang:devel Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strformat doesn't work properly inside generics
2 participants