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

NumberParser accept and ignore underscore #12479

Open
wants to merge 1 commit into
base: Pharo11
Choose a base branch
from

Conversation

privat
Copy link
Contributor

@privat privat commented Jan 30, 2023

The proposal is to extends number syntax to accept and ignore the underscore character _ (ASCII 95).

Many languages (including Python https://peps.python.org/pep-0515/ , Java https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html or Ruby) accept some forms of numeric literal that ignore _.

The idea is to permit long literals that are still readable, eg. 1_000_000_000 is easier for a human than 100000000 especially since in the previous literal a zero is missing (I'm a tricky deceitful fellow).

Usually, there is not a lot of constraint on the placement of _ to accommodate various locales and usages or radix.

However, duplicate or training _ are usually rejected as syntax error.
The PR just ignore any _ without constrains. We might add them, or add them as rules for case that feel more being a syntax warning than a syntax error.

@svenvc
Copy link
Contributor

svenvc commented Jan 30, 2023

I am not so sure it is a good idea to do this by default.
In NeoCSV I have my own number parser that supports this, as an option:

NeoNumberParser>>#digitGroupSeparator: separatorCharacter
	"Set the digit group separator to separatorCharacter.
	The are skipped while parsing digit characters.
	The default is nil (nothing being skipped)"
	
	digitGroupSeparator := separatorCharacter 

If you don't make it an option, you can't do strict checking anymore.

@guillep
Copy link
Member

guillep commented Feb 13, 2023

I'd like to have this in Pharo. I think that this can have a lot of value when working with numbers.
And I think it would be nice to to have also a number printer that adds separators...

I think this should become a phep.

@estebanlm
Copy link
Member

phep is here: pharo-project/pheps#18

please let's discuss there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: NeedsWork/Discussion
Development

Successfully merging this pull request may close these issues.

None yet

5 participants