Support numeric literal separators in source code

Description

This is stolen from Ruby, Java, Swift, Kotlin and Javascript also supports it - not sure which other languages support it but it’s really nice for readable code.

Ruby example

which is the same as

The first example is much more readable and developer friendly.

Javascript example

JS Spec

Activity

Show:

Brad Wood August 21, 2024 at 6:09 AM

Finally had a bit of time to do this tonight. This ONLY applies to the Box Script parser, not CF.

The following are valid (underscores are simply removed at compile time)

The following are invalid (throw an exception)

Since underscores are a valid identifier name, the parser doesn’t know for certain if the developer was going for a numeric literal or not, so we treat it like a normal variable.

John Whish May 21, 2024 at 3:34 PM
Edited

It might be even easier as Java seems to support it already.

This also works:

Jacob Beers May 21, 2024 at 2:30 PM

The way this is implemented in JavaScript actually allows the number separator to be used wherever you want in the number i.e. 1_0 is equal to 10. Literals cannot start with an underscore though.

This should be as easy as just making underscore a valid character in the different literal lexer rules and then stripping them out in the parser.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Priority

Sentry

Created May 21, 2024 at 8:17 AM
Updated August 21, 2024 at 6:35 AM
Resolved August 21, 2024 at 6:10 AM