Skip to content

Add Upcase ident in Macro #8210

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

Closed
wants to merge 4 commits into from
Closed

Conversation

recrack
Copy link
Contributor

@recrack recrack commented Aug 2, 2013

This feature is for rust-css colors.
see : servo/rust-css#22

something like:

define_color!(aliceblue, 240, 248, 255);

which would expand to:

static ALICEBLUE: Color = Color { red: 240, green: 248, blue: 255, alpha: 1.0 };

when is use upcaseident!(aliceblue), it can become ALICEBLUE(uppercase).

ex))

let AA = "hi"
assert!(upcase_indent!(aa)== AA);

@graydon
Copy link
Contributor

graydon commented Aug 2, 2013

Huh. I'm not so sure about this one. Synthesizing or modifying identifiers between source code and compiled form, in general, goes against the grep test (http://jamie-wong.com/2013/07/12/grep-test/) which I generally think of as worth trying to pass. Why not just pass the actual identifier ALICEBLUE into the macro?

@metajack
Copy link
Contributor

metajack commented Aug 2, 2013

It kind of sucks if you have to write define_color!(ALICEBLUE, "aliceblue"); There are a few hundred of these, and we'd have to write every color name twice just to define them. We could make all the statics lowercase, but that isn't idiomatic.

Then there is the other part of it which is macro-izing the giant match statement to parse color names. We were hoping to do parse_color!(some_str, aliceblue, antiquewhite, ...); instead of parse_color!(some_str, ALICEBLUE, "aliceblue", ANTIQUEWHITE, "antiquewhite", ...);`.

Is there another way around this such that we don't have to repeat the same characters multiple times?

@metajack
Copy link
Contributor

metajack commented Aug 2, 2013

Obviously one way around it is to write a Python script that parses a simple text file and generates the Rust code, but I was hoping to leverage the macro system instead.

@brson
Copy link
Contributor

brson commented Aug 2, 2013

If this is something that requires procedural macros but isn't appropriate for rustc maybe we could namespace it in a way that is obvious that it's not for general use, until dynamically loadable syntax extensions work, then remove it from rustc.

@brson
Copy link
Contributor

brson commented Aug 2, 2013

Or maybe we could add some macros with other support functionality such that this could be written as a macro-by-example.

@graydon
Copy link
Contributor

graydon commented Aug 2, 2013

Oh, I didn't realize the string name repeated it. That's .. More ok? I just thought I'd raise the concern, generally synthetic idents are a bit of an anti feature. Not a hard r-, if it's really needed.

@metajack
Copy link
Contributor

metajack commented Aug 2, 2013

Sorry, I slightly misspoke here. The parse_color! macro could just switch to using uppercase. But the match statement needs a string and an ident of the same name.

I suppose we could pass the grep test if we instead downcased the ident to make the string. But it would involve a very similar function to this one to turn ALICEBLUE into aliceblue and then we'd put it in quotes.

@graydon
Copy link
Contributor

graydon commented Aug 2, 2013

Maybe a variant on stringify then, yeah?

@kud1ing
Copy link

kud1ing commented Aug 27, 2013

I have written SVG parsers in the past and it appears to me that defining HTML color names is a one-off job which can be automated (in my case using copy/paste and search/replace).

Beyond rust-css where do we see this being used?

@pnkfelix
Copy link
Member

I think we should just close this pull request. The conversation between graydon and metajack shows a path towards a alternate (if similar) solution for color names that does not break the grep test: namely, a variant on stringify that downcases. (Unless someone comes up with a real-world use case that cannot be re-encoded in a reasonable way given that hypothetical stringify_downcase! macro.)

@brson
Copy link
Contributor

brson commented Aug 28, 2013

Closing per @pnkfelix

@brson brson closed this Aug 28, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 13, 2022
Add borrow_as_ptr lint

Closes: rust-lang#6995

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: new lint: [`borrow_as_ptr`]
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.

6 participants