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

Fix parsing oct and hex numbers #364

Merged
merged 1 commit into from
Jun 15, 2022
Merged

Fix parsing oct and hex numbers #364

merged 1 commit into from
Jun 15, 2022

Conversation

qzb
Copy link
Contributor

@qzb qzb commented Feb 7, 2022

Fixes #363

geseq
geseq previously approved these changes Feb 7, 2022
Copy link
Collaborator

@geseq geseq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Owner

@d5 d5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. When I tested the following code at the VM-level:

expectRun(t, `out = 1 + 010`, nil, 9)    // works
expectRun(t, `out = 1 + 0x10`, nil, 17)  // works
expectRun(t, `out = 1 + 0o10`, nil, 9)   // Parse Error: expected ';', found o10
expectRun(t, `out = 1 + 0b10`, nil, 3)   // Parse Error: expected ';', found b10

I think we should fix this too if we want to fully support the binary/octal numbers?

@qzb
Copy link
Contributor Author

qzb commented Feb 9, 2022

@d5 I've rewritten numbers scanning from scratch. Instead of trying to scan only valid numbers, it scans for things resembling number and let strconv do the validation. It should be fully compatible with golang's int and float literals.

If you don't like those changes, I can revert them and add support only for literals you mentioned.

Copy link
Collaborator

@geseq geseq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

@geseq
Copy link
Collaborator

geseq commented Jun 12, 2022

@d5 will need your approval as well

@geseq geseq merged commit 6fc27de into d5:master Jun 15, 2022
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.

All ints are parsed in base 10
3 participants