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

text/scanner: Scanner parsing "1000Possibilities" as float #46322

Closed
andbelo opened this issue May 22, 2021 · 3 comments
Closed

text/scanner: Scanner parsing "1000Possibilities" as float #46322

andbelo opened this issue May 22, 2021 · 3 comments

Comments

@andbelo
Copy link

andbelo commented May 22, 2021

What version of Go are you using (go version)?

$ go version
The Go Playground
In the computer, 1.16.4
https://golang.org/pkg/text/scanner/#pkg-overview

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
https://golang.org/pkg/text/scanner/#pkg-overview

What did you do?

Scanned a token with a number followed by a missing space before a word that started with a 'P' or a 'p'
https://play.golang.org/p/x2e4I1kp7BN

What did you expect to see?

Parsing of 1000Possibilities as the string "1000Possibilities"

What did you see instead?

example:1:69: 'P' exponent requires hexadecimal mantissa
example:1:69: exponent has no digits
example:1:69: 1000P
example:1:74: ossibilities

@seankhliao seankhliao changed the title scanner.Scanner misinterpreting \dP as a number text/scanner: Scanner parsing 1000Possibilities as float May 22, 2021
@seankhliao seankhliao changed the title text/scanner: Scanner parsing 1000Possibilities as float text/scanner: Scanner parsing "1000Possibilities" as float May 22, 2021
@robpike
Copy link
Contributor

robpike commented May 22, 2021

The package scans Go tokens, and 1000Possibilities is not a valid Go token. The only problem here, if there is one at all, is that the error might be improvable but it's equivalent to the error given by the Go compiler:

https://play.golang.org/p/gjVzu7spj1W

./prog.go:4:11: 'P' exponent requires hexadecimal mantissa
./prog.go:4:12: syntax error: unexpected ossibilities at end of statement

@ianlancetaylor
Copy link
Contributor

If you don't want to scan Go tokens, you need to change the scanner Mode field.

Closing because this is not a bug.

@andbelo
Copy link
Author

andbelo commented May 23, 2021 via email

@golang golang locked and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants