Skip to content

strconv: document exact grammar of Parse{Float,Int,Uint} #31197

@dsnet

Description

@dsnet

strconv.Parse{Float,Int,Uint} is frequently used in the implementation of other grammars (e.g., JSON), which may be a subset or superset of what strconv.ParseX currently does today. However, what strconv.Parse does today is not well-specified. What exactly is the input grammar that is accepted?

For example, the documentation for ParseFloat only says "If s is well-formed", but does not specify what "well-formed" means. I suspect that the answer to this is whether the input is well-formed according to the grammar in the Go specification. If so, this needs to be documented.

Furthermore, this also opens the question for whether the input grammar is stable. Apparently, this is not the case since strconv.ParseX was recently augmented to support the new number literal grammars (CL/160241 and CL/160244). This change is going to silently break a number of use-cases that were assuming that the input of ParseX was constrained to the grammar prior to Go1.13. If so, the instability of the input grammar should also be documented.

(BTW, I think the change in semantics is entirely reasonable and I support it; but I see a lot of code silently broken by this change. Documenting this better would help dissuade future abuse.)

\cc @cybrcodr, @griesemer, @rsc

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions