Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: design of the tr! macro #1
Comments
ogoffart
changed the title
RFC: desing of the tr! macro
RFC: design of the tr! macro
Nov 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ogoffart commentedNov 25, 2018
Syntax
Current syntax:
I chose the oprator
=>,|and%because out of all possible operator or keywords, this was what seemed to me the most logical. I was considering puting thecountvariable before the string, butthat makes the macro difficult to parse because only some token are allowed after an
exprin a macro, and=>was already taken for the contextAnother possibility could be, for example
But
@is a bit more alien. Or maybe that'd actually be better?(other possible contex separator itoken includes
;,#or$, or maybe keywords)Other suggestions are welcome.
Return Type
What should be the type of the tr! expression? Currently it is a
String, which is probably the easier to use. Alternatiely, this could be a type whiwh could be implementing Display and possibly other trait, it would allowMaybe another macro name could be used, or a keyword inside the macro to vary the return type.
Formating
If we want to support translation script based on the argument, we need to have the arguments within the same macro. I think it is better to have the same formating as the format! macro, as everybody is familiar with that (currently, not everything is implemented, but that can be solved).
The question is what to do when the formating contains error. Panicing is not a good idea, as we do not want to crash the program when a translation is invalid. Returning an error is not making the all site convininent. So I currently try to make best effort to recover. And perhaps showing an error on stderr could be done.