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

RFC to lex binary and octal literals more eagerly. #879

Merged
merged 2 commits into from
Mar 30, 2015

Conversation

huonw
Copy link
Member

@huonw huonw commented Feb 17, 2015

@aidancully
Copy link

The part that still strikes me as awkward is that suffixes have an invisible constraint (as in, not obvious at the point where the suffix lexeme would be described) that they not begin with the characters [a-fA-F], in order to avoid an ambiguity with hexadecimal numbers. I can't think of a current-rust compatible way to avoid that issue, though. (The best incompatible way of dealing with the issue is, I think, to eliminate suffixes and use type-ascription instead. Which is probably a big lift, but I'd suggest could be mentioned under Alternatives?)

@huonw
Copy link
Member Author

huonw commented Feb 17, 2015

While that is a reasonable point (a user-defined suffix must not start with a valid hex char to be usable with hexidecimal literals), I'm not sure it's relevant to this RFC in particular.

That is, even if we had no suffixes, I would still be in favour of this more eager lexing.

@aidancully
Copy link

If we had no suffixes, the lexing should be even more eager ([0-9][0-9a-zA-Z_]*), but that's not an argument against your solution, which I'd support: this seems like an obvious bug in the lexing, to me.

@Ericson2314
Copy link
Contributor

What about ([0-9]+ | 0(o|b|x)[0-9a-fA-F]+) suffix to take the RFC one step further? I also like eager lexing.

@huonw
Copy link
Member Author

huonw commented Feb 18, 2015

@Ericson2314 good point! In this case, I think we automatically effectively get that grammar with this change (well, the ability to switch to it backwards compatibly), since e.g. 0b101ABC1234 is lexed as 0b101 with a suffix of ABC1234.

@aidancully
Copy link

There's probably an obvious reason this won't work, but what about requiring suffix to begin with :? It avoids the ambiguity with potential future suffixes that begin with [a-fA-F], and might be future compatible with using type-ascription to specify variable types? It'd basically be a limited form of type-ascription, but only for definitions that have suffixes.

@Ericson2314
Copy link
Contributor

@aidancully Interesting! In Haskell type ascription has very low precedence, but this allows a maximally high precedence type ascription to be introduced replacing the lexing suffixes trick backwards compatibly.

@CloudiDust
Copy link
Contributor

@aidancully @Ericson2314, +1, this is a neat way to avoid duplicating features once "full" type ascriptions land.

steveklabnik added a commit that referenced this pull request Mar 30, 2015
RFC to lex binary and octal literals more eagerly.
@steveklabnik steveklabnik merged commit 51dd32f into rust-lang:master Mar 30, 2015
@steveklabnik
Copy link
Member

Accepted! I'm not going to make a tracking issue, since @huonw already has a patch prepared.

huonw added a commit to huonw/rust that referenced this pull request Mar 31, 2015
Previously 0b12 was considered two tokens, 0b1 and 2, as 2 isn't a valid
base 2 digit. This patch changes that to collapse them into one (and
makes `0b12` etc. an error: 2 isn't a valid base 2 digit).

This may break some macro invocations of macros with `tt` (or syntax
extensions) that rely on adjacent digits being separate tokens and hence
is a

[breaking-change]

The fix is to separate the tokens, e.g. `0b12` -> `0b1 2`.

cc rust-lang/rfcs#879
@Centril Centril added the A-syntax Syntax related proposals & ideas label Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntax Syntax related proposals & ideas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants