x/mod/modfile: scan ASCII bracket characters and commas as separate tokens #38167
Labels
FrozenDueToAge
GoCommand
cmd/go
modules
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
The
go.mod
parser treats the characters(
and)
as separate tokens if they appear after whitespace characters or after the end of another token. They are not treated as separate tokens if they appear after other non-whitespace characters though.This is making it difficult to add new syntax, such as the version ranges suggested in #24031. It's also a problem that parentheses are the only recognized bracket character.
Ideally, the bracket characters (
( ) [ ] { }
) and the comma (,
) would be scanned as separate characters when unquoted, regardless of surrounding whitespace characters.None of these characters are allowed in module paths or versions, but they are allowed in file paths and may appear on the right side of a
replace
directive. So for the sake of compatibility, we should make this change in two steps:[ ] { } ,
should be scanned as separate tokens when preceded by whitespace. These are not valid at the beginning of any token today (including file paths), so this should be safe to do immediately. The characters(
)
are already scanned this way.retract
), the characters( ) [ ] { } ,
are scanned as separate tokens, even when preceded by non-whitespace characters in all directives. Old versions of thego
command don't need to scan these directives correctly.go.mod
is formatted. So the path./foo()
will be automatically rewritten as"./foo()"
.( ) [ ] { } ,
are scanned as separate tokens, even when preceded by non-whitespace characters in all directives.Blocks #24031
Related #38144
cc @bcmills @matloob @rsc
The text was updated successfully, but these errors were encountered: