You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow _ for readability in unitized constants like 3_day or 5_gb #9111
〉3day
3day
〉3_day
Error: nu::shell::external_command
× External command failed
╭─[entry #14:1:1]
1 │ 3_day
· ──┬──
· ╰── executable was not found
╰────
help: No such file or directory (os error 2)
Describe the solution you'd like
So one could say:
let duration = 3.165_hours
let size = 1.234_567__mb
Using _ for improving readability of numeric constants is a great idea. Why not extend it to unitized constants of all types? Duration, Filesize, (what's the complete list of these?)
I'd support this, only if it was in addition to what we have. I like what you said in another issue that there should be multiple ways to express this. e.g.
Yes, it could be a pure add.
This is a good first project for an aspiring parser hacker, documented here for anyone who wants to take a crack at it.
The routines that parse Duration and Filesize are pretty straightforward. Each has a list of suffixes and you could add more easily.
If you only worry about underscores between the numeric and suffix part, each has just one place you'd have to do that scan. (fully general placement would allow underscores in the numeric part too, Nu allows this for ints and float literals now.)
The hardest part would be adding enough test cases for the new syntax. I recommend rstest, it's already in the project.
Just to make this an even more inviting first parser project for someone...
The above would allow duration or filesize literals you type into Nu to include underscores.
To have the duration print with an underscore, see TimePeriod::to_text(). If you add underscores before these duration units, they will print out just fine.
Filesize is a bit of a puzzle, I don't have any suggestions for it yet.
Activity
fdncred commentedon May 5, 2023
I'd support this, only if it was in addition to what we have. I like what you said in another issue that there should be multiple ways to express this. e.g.
etc
bobhy commentedon May 6, 2023
Yes, it could be a pure add.
This is a good first project for an aspiring parser hacker, documented here for anyone who wants to take a crack at it.
The routines that parse Duration and Filesize are pretty straightforward. Each has a list of suffixes and you could add more easily.
If you only worry about underscores between the numeric and suffix part, each has just one place you'd have to do that scan. (fully general placement would allow underscores in the numeric part too, Nu allows this for ints and float literals now.)
The hardest part would be adding enough test cases for the new syntax. I recommend
rstest, it's already in the project.bobhy commentedon May 7, 2023
Just to make this an even more inviting first parser project for someone...
The above would allow duration or filesize literals you type into Nu to include underscores.
To have the duration print with an underscore, see TimePeriod::to_text(). If you add underscores before these duration units, they will print out just fine.
Filesize is a bit of a puzzle, I don't have any suggestions for it yet.
fdncred commentedon May 7, 2023
It would be also be nice if plurals could be used when appropriate.
improve parsing of values with units (#9190)