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

Implement hexadecimal floating point literals via a syntax extension #12652

Merged
merged 1 commit into from
Mar 11, 2014

Conversation

rcxdude
Copy link
Contributor

@rcxdude rcxdude commented Mar 2, 2014

Closes #1433. Implemented after suggestion by @cmr in #12323

This is slightly less flexible than the implementation in #12323 (binary and octal floats aren't supported, nor are underscores in the literal), but is cleaner in that it doesn't modify the core grammar, or require odd syntax for the number itself. The missing features could be added back with relatively little effort (the main awkwardness is parsing the string. Is there a good approach for this in the stdlib currently?)

@brson
Copy link
Contributor

brson commented Mar 3, 2014

While I thank you for this PR, I question whether this feature deserves its own crate in the main rust distribution.

@rcxdude
Copy link
Contributor Author

rcxdude commented Mar 3, 2014

I was basing the design of the fourcc! macro. Is there a better way to arrange syntax extensions?

@Kimundi
Copy link
Member

Kimundi commented Mar 3, 2014

@brson Imo we should support at least some kind of hex float literals in the main distribution (syntaxext or literal).

Having only base 10 literals means specifying an bit-exact float value becomes almost impossible.

let mut chars = s.chars().peekable();
let mut i = 0;
if *chars.peek().unwrap_or(&'_') == '-' { chars.next(); i+= 1 }
if chars.next().unwrap_or('_') != '0' { return Some((i, ~"Expected '0'")); } i+=1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if chars.next() != Some('0')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be neater. Thanks! I'm still learning to think in terms of rust.

@brson
Copy link
Contributor

brson commented Mar 6, 2014

@rcxdude Understood re the fourcc crate (I'm not sure how I feel about that crate either).

We don't have a lot of precedent for adding syntax extensions outside of rustc. I'd like to hear @alexcrichton and @pcwalton's opinions about how we should be evaluating and organizing these.

@rcxdude
Copy link
Contributor Author

rcxdude commented Mar 6, 2014

It seems that it would be fairly easy to group syntax extensions into their own crate. However it would work a lot better if macros were more similar to other objects in terms of their interaction with crates, e.g.
use foo::macro1!; foo::macro2!(bar, baz); etc, etc...

I'm interested in working on this, as well as other macro features.

@eddyb
Copy link
Member

eddyb commented Mar 6, 2014

@rcxdude sadly, it's not that easy... My plans involve intertwining expansion with resolve, for performance and features like that (and more hygiene etc.).
If nobody has anything against it, I'd suggest starting to remove every pass between expansion and resolve.
Right now it's just a waste of compile time, folding again and again to make tiny changes that can instead go in the parser, expansion or resolve.

@alexcrichton
Copy link
Member

I'm as ok with including this as I am with fourcc. I think it's fine for now until we get a package manager at which point these should probably move out of the repo.

Syntax extensions and their tests are always pain points in snapshots, cross compilation, and in general due to how flaky they are.

@alexcrichton
Copy link
Member

Can you squash these commits? Other than that, I think this is ready to go.

@rcxdude
Copy link
Contributor Author

rcxdude commented Mar 9, 2014

done.

@rcxdude
Copy link
Contributor Author

rcxdude commented Mar 10, 2014

Sorry about the test failure. Looks like #[feature(phase)]; doesn't play well with check-fast, I've added ignore-fast to it.

bors added a commit that referenced this pull request Mar 11, 2014
Closes #1433. Implemented after suggestion by @cmr in #12323

This is slightly less flexible than the implementation in #12323 (binary and octal floats aren't supported, nor are underscores in the literal), but is cleaner in that it doesn't modify the core grammar, or require odd syntax for the number itself. The missing features could be added back with relatively little effort (the main awkwardness is parsing the string. Is there a good approach for this in the stdlib currently?)
bors added a commit that referenced this pull request Mar 11, 2014
Closes #1433. Implemented after suggestion by @cmr in #12323

This is slightly less flexible than the implementation in #12323 (binary and octal floats aren't supported, nor are underscores in the literal), but is cleaner in that it doesn't modify the core grammar, or require odd syntax for the number itself. The missing features could be added back with relatively little effort (the main awkwardness is parsing the string. Is there a good approach for this in the stdlib currently?)
@bors bors closed this Mar 11, 2014
@bors bors merged commit a38e148 into rust-lang:master Mar 11, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
internal: Try to publish releases to OpenVSX
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 18, 2024
Fix markdown syntax in str_split_at_newline docs

changelog: [`str_split_at_newline`] Fix formatting of docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for hexadecimal float literals
6 participants