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

Support hex and other numbers in ranges #345

Merged
merged 3 commits into from
Feb 8, 2023
Merged

Support hex and other numbers in ranges #345

merged 3 commits into from
Feb 8, 2023

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Feb 8, 2023

Fixes #342

Originally, I used eval, because at this point we should have guaranteed that the Literal is of a reasonable form. But this seems a little risky. Instead I switched to parseInt which seems to cover the cases we care about (given CoffeeScript's weird semantics with floats).

I tried to get BigInt literals to work too, but they're annoying to work with because even += 1 doesn't work (can't mix BigInts with regular numbers). Anyway, they're unlikely to be useful, as they likely have length more than 20.

@edemaine edemaine temporarily deployed to build February 8, 2023 16:06 — with GitHub Actions Inactive
@STRd6
Copy link
Contributor

STRd6 commented Feb 8, 2023

Needs one more check to support:

[0..0b10]
[0..0o10]

https://coffeescript.org/#try:%5B0..0b10%5D%0A%5B0..0o10%5D

@edemaine edemaine temporarily deployed to build February 8, 2023 17:55 — with GitHub Actions Inactive
@edemaine
Copy link
Collaborator Author

edemaine commented Feb 8, 2023

Oof, I didn't realize parseInt doesn't automatically recognize binary or octal literals.

I ended up writing a general module.literalValue helper. Could be worth another review.

@edemaine edemaine merged commit 50f594e into main Feb 8, 2023
@edemaine edemaine deleted the hex-range branch February 8, 2023 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coffeescript bug: can't handle hex in range expression
2 participants