-
-
Notifications
You must be signed in to change notification settings - Fork 661
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
Implement number separator #10480
Comments
Now that I'm looking at this we might have been a bit too quick to fully consider this. Since this opens up more accepted syntax which is visible to macros, there will be questions about support for this new syntax. This is going to have ramifications for I originally thought that we would just discard the |
Isn't that true of the numeric suffixes as well? It might be good to provide an API for macros to extract values from |
I expect that those are dealt with by a second optional argument to |
Sure, but if it is |
Yeah well, it's a good thing we don't talk about parsing so much regarding that feature! Unlike the separator, it's easy to argue (and document) that the suffix is not part of the literal and that the best the run-time could do with it is ignore it, which I think it already does anyway. |
String literals also don't necessarily contain the exact source: https://try.haxe.org/#5f35A102 I suppose the question is more relevant whether or not someone will want to perform some shenanigans based on the separators, but since any binary operator may be used to syntactically string together groups of digits I'd say those use cases are already covered. |
Would it work to have the numbers as an abstract. That way they have no impact on Float's and Int's directly and any side effects or bugs that are created are limited to use of these special abstracts. I don't know how it would look... |
Would it be allow combination with #10481 as for example |
This is the macro case we'll have to look into: import haxe.macro.Expr;
macro function test(e:Expr) {
switch (e.expr) {
case EConst(CInt(s)):
trace(s); // 1_2
trace(Std.parseInt(s)); // 1
case _:
}
return macro null;
}
function main() {
test(1_2);
}
Yes. We don't allow trailing |
Maybe turning |
I think it's enough if we adapt the macro version of |
Technically this is a breaking change, because
So if anybody relied on |
... and then we're also back to the problem that |
* [lexer] accept `_` as number separator see #10480 * add some tests * deal with generators * well whatever * allow _f64
I don't like that |
At this point I think you're right. I originally wanted the separator to be completely invisible, but I realize that this isn't going to be the case at syntactic level anyway. Nor should it be, because I'll think about it a bit more, but I'll probably just close this issue then. |
Yeah this is fine! |
Have implemented a simple String->String parser with StringBuffer in pure haxe with no macros, it is suitable for parsing runtime user String ( within xml/json feeds ) into a format suitable for current parseInt and parseFloat. It could be tweaked and added to StringTools, if that seem a good route, without any backwards compatibility concerns, and could be used directly only when a developer required the extra safety or wished to allow users to use commas in numbers, obviously it could be optimised per target in the future. https://github.com/nanjizal/parseNumber Currently it is functional in js and c++ targets, although it should work in all. |
See HaxeFoundation/haxe-evolution#90
The text was updated successfully, but these errors were encountered: