Skip to content

Added support for binary int literals - #550

Merged
JukkaL merged 1 commit into
python:masterfrom
andersschuller:binary-int-literals
Jan 4, 2015
Merged

JukkaL merged 1 commit into
python:masterfrom
andersschuller:binary-int-literals

Conversation

@andersschuller

Copy link
Copy Markdown
Contributor

This should fix #534.

As part of this change, I changed the parsing of int expressions to use int(token, base=0). As noted in the Python docs, "base 0 means to interpret exactly as a code literal, so that the actual base is 2, 8, 10, or 16". This means all four cases are handled in one, and parse_int_expr now looks more like parse_float_expr and parse_complex_expr.

Also, I was going to add a test similar to test_invalid_hex_int_literals for octal and binary literals, but I discovered the lexer currently allows invalid octal literals like 0oA. The same is true for binary literals after this change. Is it worth updating the regular expression to only allow valid literals? I think something like 0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+|[0-9]+ should work.

This is my first contribution to the project, so please let me know if I have missed anything or if you have any questions.

@JukkaL

JukkaL commented Jan 4, 2015

Copy link
Copy Markdown
Collaborator

Thanks for implementing this! Looks good. The issue with invalid literals can be fixed as a separate task, since it's not directly related to binary int literals.

JukkaL added a commit that referenced this pull request Jan 4, 2015
Added support for binary int literals
@JukkaL
JukkaL merged commit c84a07d into python:master Jan 4, 2015
@andersschuller
andersschuller deleted the binary-int-literals branch January 5, 2015 19:56
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.

Support 0b int literals

2 participants