Feature #14269
closedmdb could support separators in numbers
100%
Description
Other languages, such as rust, have the ability to add separators in numbers. For example, 0x123456
can be written as 0x123_456
. Strictly speaking, arbitrary _
characters can be inserted into a number after the first actual digit in the number. Thus 0x1_2_3_________4___
is valid. Ultimately, this makes trying to type long hex addresses by hand, a lot less error prone.
While the use of _
is a bit arbitrary, the fact that it's used in rust, in documentation from a large number of languages, e.g. it was present in at least Java 7 and Python. The Python link includes prior art in a number of other languages such as C3, D, Julia, Ruby, Switch, etc.
The final set of rules that we adhere too are based on the Rust Reference. Basically:
- The base if not present acts as it does today, by using the current set base in mdb (hex by default)
- There must be a leading digit, before an underscore
- Afterwards there are any number of underscores that can be interspersed with digits
- When using a non-prefixed number (e.g.
f00
or_ba12
), mdb will still look up symbols before treating it as a number (this is part of the existing grammar).
Updated by Robert Mustacchi almost 2 years ago
I've tested this in a few ways. With the mdb test suite:
rm@beowulf:~$ /opt/util-tests/tests/mdb/mdbtest Starting tests... mdbtest target: /usr/bin/mdb output directory: /var/tmp/mdbtest.1739 Executing test ./options/tst.autowrap.mdb ... passed Executing test ./typedef/err.badmodel.ksh ... passed Executing test ./typedef/tst.deftypes64.mdb ... passed Executing test ./typedef/err.noargs.ksh ... passed Executing test ./typedef/err.badstruct-noarrayopen.ksh ... passed Executing test ./typedef/tst.union.mdb ... passed Executing test ./typedef/tst.deftypes32.mdb ... passed Executing test ./typedef/tst.structselfref.mdb ... passed Executing test ./typedef/tst.cleanupstruct.ksh ... passed Executing test ./typedef/tst.emptylist.mdb ... passed Executing test ./typedef/err.badstruct-nomemname.ksh ... passed Executing test ./typedef/err.badstruct-zerolenarr.ksh ... passed Executing test ./typedef/err.badstruct-nomembers.ksh ... passed Executing test ./typedef/tst.anonstruct.mdb ... passed Executing test ./typedef/tst.models.ksh ... passed Executing test ./typedef/err.badstruct-noarraylen.ksh ... passed Executing test ./typedef/err.badstruct-nobraces.ksh ... passed Executing test ./typedef/tst.dellist.mdb ... passed Executing test ./typedef/err.badstruct-repmemname.ksh ... passed Executing test ./typedef/err.extraargs.ksh ... passed Executing test ./typedef/err.badstruct-neglenarr.ksh ... passed Executing test ./typedef/err.badstruct-noarrayclose.ksh ... passed Executing test ./typedef/err.nokeyword.ksh ... passed Executing test ./typedef/err.typeexists.ksh ... passed Executing test ./typedef/err.badid-leadschar.ksh ... passed Executing test ./typedef/tst.structvla.mdb ... passed Executing test ./typedef/tst.struct.mdb ... passed Executing test ./typedef/err.badstruct-nomemsemi.ksh ... passed Executing test ./typedef/err.badunion-hasvla.ksh ... passed Executing test ./typedef/err.badstruct-noclosebrace.ksh ... passed Executing test ./typedef/tst.libctype.ksh ... passed Executing test ./typedef/err.badstruct-noquotes.ksh ... passed Executing test ./typedef/err.noname.ksh ... passed Executing test ./typedef/tst.anonunion.mdb ... passed Executing test ./typedef/err.badstruct-vlaonly.ksh ... passed Executing test ./typedef/err.nomodel.ksh ... passed Executing test ./typedef/err.badid-leadnum.ksh ... passed Executing test ./typedef/err.badstruct-noopenbrace.ksh ... passed Executing test ./typedef/err.badstruct-extrabraces.ksh ... passed Executing test ./exit-e/err.unmapped.ksh ... passed Executing test ./exit-e/tst.simple.ksh ... passed Executing test ./exit-e/err.nowrite.ksh ... passed Executing test ./exit-e/err.enocmd.ksh ... passed Executing test ./exit-e/tst.output.ksh ... passed Executing test ./exit-e/err.cmdbadopt.ksh ... passed Executing test ./numbers/tst.badnums.ksh ... passed Executing test ./numbers/tst.base10.mdb ... passed Executing test ./numbers/tst.octal.mdb ... passed Executing test ./numbers/tst.prefsym.ksh ... passed Executing test ./numbers/tst.hex.mdb ... passed Executing test ./numbers/tst.binary.mdb ... passed Executing test ./numbers/tst.bitfields.ksh ... passed Executing test ./format/tst.format-cap-J.mdb ... passed Executing test ./format/tst.format-g.mdb ... passed Executing test ./format/tst.format-cap-P.mdb ... passed Executing test ./format/tst.format-cap-E.mdb ... passed Executing test ./format/tst.format-e.mdb ... passed Executing test ./format/tst.format-p.mdb ... passed Executing test ./format/tst.format-cap-G.mdb ... passed Executing test ./format/tst.format-j.mdb ... passed Executing test ./format/tst.format-cap-R.mdb ... passed ------------- Results ------------- Tests passed: 61 Tests failed: 0 Tests ran: 61 Congrats, mdb isn't completely broken, the tests pass.
I also did manual testing of this and using it. Finally, I also spot checked other test suites which all passed:
- util-tests
- os-tests
- libc-tests
- elf-tests
Updated by Electric Monk almost 2 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
git commit f32691c936d40863e9f2c96ce452c6208bd056f2
commit f32691c936d40863e9f2c96ce452c6208bd056f2 Author: Robert Mustacchi <rm@fingolfin.org> Date: 2022-01-15T00:41:16.000Z 14269 mdb could support separators in numbers Reviewed by: Jason King <jason.brian.king@gmail.com> Reviewed by: Andy Fiddaman <andy@omnios.org> Approved by: Rich Lowe <richlowe@richlowe.net>