]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: accept new Go2 number literals
authorRobert Griesemer <gri@golang.org>
Sun, 13 Jan 2019 04:33:58 +0000 (20:33 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 11 Feb 2019 23:22:50 +0000 (23:22 +0000)
commitceb849dd97aebf08eee5f3683619494c56190f81
tree6616c63bbe055299c882fe78bc4514ce16ca615a
parent7bc2aa670f47266d3c5a840d748a1f2e805b89d7
cmd/compile: accept new Go2 number literals

This CL introduces compiler support for the new binary and octal integer
literals, hexadecimal floats, and digit separators for all number literals.

The new Go 2 number literal scanner accepts the following liberal format:

number   = [ prefix ] digits [ "." digits ] [ exponent ] [ "i" ] .
prefix   = "0" [ "b" |"B" | "o" | "O" | "x" | "X" ] .
digits   = { digit | "_" } .
exponent = ( "e" | "E" | "p" | "P" ) [ "+" | "-" ] digits .

If the number starts with "0x" or "0X", digit is any hexadecimal digit;
otherwise, digit is any decimal digit. If the accepted number is not valid,
errors are reported accordingly.

See the new test cases in scanner_test.go for a selection of valid and
invalid numbers and the respective error messages.

R=Go1.13

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Change-Id: Ic8febc7bd4dc5186b16a8c8897691e81125cf0ca
Reviewed-on: https://go-review.googlesource.com/c/157677
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/gc/mpfloat.go
src/cmd/compile/internal/gc/mpint.go
src/cmd/compile/internal/syntax/scanner.go
src/cmd/compile/internal/syntax/scanner_test.go
src/go/types/stdlib_test.go
test/fixedbugs/issue9036.go
test/literal2.go [new file with mode: 0644]