elahn
August 10, 2017, 12:40am
1
I’ve looked through the token list and selected tokens that can be more or less usable for other-crate-relative paths without ambiguities (including “inline” non-use
paths).
Most of tokens were thrown away immediately because they can be used as binary/unary operators and they can be used freely with paths in expressions.
I tried to not introduce new tokens for this, but in principle ~
can be used regardless of syntax details because it’s unused at the moment, or the backslash token (\
) can be added to the language (can’t say I’m a fan though).
There are roughly three groups of possible syntaxes:
a INFIX b::c
OPEN_DELIM a CLOSE_DELIM b::c
PREFIX a::b::c
INFIX
variants look universally bad, IMO, mostly because they break the path into separate parts.
a _ b::c
a::_::b::c
a crate b::c
a:\b::c // Windows drive letters!
a#b::c
a#::b::c
// etc
OPEN_DELIM a CLOSE_DELIM
variants look better.
[a]::b::c
(a)::b::c
{a}::b::c
// but not <a>::b::c, it's already taken
PREFIX a::b::c
(1) keywords.
From all keywords only crate
, extern
and in
looks somehow relevant.
// Less noise
extern a::b::c
crate a::b::c
in a::b::c
// More noise
extern::a::b::c
crate::a::b::c
in::a::b::c
PREFIX a::b::c
(2) sigils, look kinda random.
_ a::b::c
_::a::b::c
#a::b::c
#::a::b::c
~a::b::c
~::a::b::c
Aaaand… ta-da!
@a::b::c
is not actually ambiguous!11
@
can currently be used only in patterns like this ref? mut? IDENT @ PATTERN and IDENT PATH
is never a valid token sequence,
so ident @a::b::c
is unambiguously a pattern (ident @ a::b::c == IDENT @ PATTERN
) and not ident @a::b::c == IDENT PATH
, because
the latter is not a valid syntax.
Basically, the three most viable syntaxes were already discussed in various threads:
// The least noisy syntax, and well fitting because `@` has "location" semantics.
@a::b::c
// Slightly more noisy syntax, and memorable because `[ ### ]` is a *crate*.
[a]::b::c
// The "no sigils" variant, good if `use extern a;` will be used roughly like
// `extern crate a;` is used now, with "inline" uses being rare. Probably too
// wordy if used more often (e.g. in every `use` import).
extern a::b::c
Note: this poll includes “inline” non-use paths
@a::b::c
[a]::b::c
extern a::b::c
I checked extern a::b::c
, though I’d certainly prefer extern::a::b::c
because of more regularity across the full path. It’s an extension of self::
and super::
to me.
So I vote for the non-listed extern::cratename::b::c
.
4 Likes
I should also note, while @foo::bar
is not ambiguous, it would make foo@@bar::Baz
a valid pattern.
elahn
August 10, 2017, 1:19am
4
Sorry, I can’t add it to the poll as > 5 mins have passed, but a moderator can…Until then, if anyone wants to vote for extern::a::b::c
, please like @phaylon ’s comment
1 Like
There isn’t an option for “don’t do this, please”.
10 Likes
system
Closed
March 25, 2019, 8:28am
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.