Skip to content

Add binary literals and underscore separators to number literals - #352

Draft
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:number-literal-separators
Draft

Add binary literals and underscore separators to number literals#352
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:number-literal-separators

Conversation

@fmeum

@fmeum fmeum commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Extends the lexical grammar for number literals in two ways:

  • Binary integer literals (0b1011/0B1011): these are documented in the go.starlark.net language description and partially implemented in the Java lexer, but were missing from the spec. Fixes spec: 0b10101 binary literals #117.
  • Underscore digit separators (PEP 515): a single _ may appear between two digits of an int or float literal, or between a base prefix and the first digit (e.g. 1_000_000, 0xFFFF_FFFF, 0x_FF, 1_000.000_1). Underscores have no effect on the value.

Following Python, the spec also states that it is an error if a literal's digits are immediately followed by a decimal digit that is not valid in the literal's base (e.g. 0o12345678 is an error rather than the two tokens 0o1234567 and 8).

This is the spec counterpart to the Java implementation in bazelbuild/bazel#29784, requested in this review.

🤖 Generated with Claude Code

Adds 0b/0B binary integer literals and PEP 515-style underscore
separators between digits to the lexical grammar for int and float
literals.

Fixes bazelbuild#117

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@google-cla

google-cla Bot commented Jun 10, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@brandjon

Copy link
Copy Markdown
Member

(CLA is false positive due to claude attribution)

@brandjon brandjon self-assigned this Jun 15, 2026
Comment thread spec.md
group digits for readability and have no effect on the value of the
literal.

It is a static error if the digits of a number literal are immediately

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would delete this second paragraph. I believe in all cases it is already a static error regardless of this text, so all the paragraph is doing is specifying that it's a lexical error rather than a parsing one, which is really an implementation detail.

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.

spec: 0b10101 binary literals

2 participants