-
Notifications
You must be signed in to change notification settings - Fork 136
Rewrite procedural macro based on the enum discriminant trick #123
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It could be useful outside of cssparser.
r? @nox Do not merge yet, I’ll port Servo and figure out how to land it without breaking Firefox too much… |
5 tasks
r=me |
SimonSapin
added a commit
to servo/servo
that referenced
this pull request
Feb 28, 2017
5 tasks
bors-servo
pushed a commit
to servo/servo
that referenced
this pull request
Feb 28, 2017
Update cssparser <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15766) <!-- Reviewable:end -->
@bors-servo r=nox |
📌 Commit 4a46a54 has been approved by |
bors-servo
pushed a commit
that referenced
this pull request
Feb 28, 2017
Rewrite procedural macro based on the enum discriminant trick We can improve on this with an idea from @dtolnay: ```rust enum Dummy { Input = (0, stringify!( ... )).0 } ``` Instead of a custom attribute, we use an enum with an explicit discriminant (because that’s the only case where a type definition can contain a (const) expression), together with accessing the first field of a literal tuple to ignore other fields. Instead of just string literals, we can accept arbitrary tokens that `stringify!` will later be expanded into something parseable in a const expression context. (`stringify!` doesn’t help in attributes because it is not yet expanded by the time anything other than string literals is rejected.) The details of this hack are hidden away into a new crate, called [`procedural-masquerade`](https://docs.rs/procedural-masquerade/). ---- This enables concrete benefits for users of cssparser: * `match_ignore_ascii_case!` now supports the full syntax of `match` expressions, including alternatives `pattern | other_pattern`, bindings `name @ pattern`, and guards `pattern if condition`. * Map values in `asci_case_insensitive_phf_map!` are now given literally instead of as string literals containing Rust syntax. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/123) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
SimonSapin
added a commit
to servo/servo
that referenced
this pull request
Feb 28, 2017
bors-servo
pushed a commit
to servo/servo
that referenced
this pull request
Feb 28, 2017
Update cssparser <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15766) <!-- Reviewable:end -->
moz-v2v-gh
pushed a commit
to mozilla/gecko-dev
that referenced
this pull request
Mar 1, 2017
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 0be96fc61d6e7a157d88ce68c85a94344dc46d8e
Manishearth
pushed a commit
to Manishearth/gecko-dev
that referenced
this pull request
Mar 9, 2017
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f
JerryShih
pushed a commit
to JerryShih/gecko-dev
that referenced
this pull request
Mar 13, 2017
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f
clementmiao
pushed a commit
to clementmiao/servo
that referenced
this pull request
Apr 7, 2017
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-comments-removed
that referenced
this pull request
Oct 1, 2019
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f UltraBlame original commit: 7b1716fa9983b0662773fea92eb8847edb65557c
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-wordified
that referenced
this pull request
Oct 1, 2019
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f UltraBlame original commit: 7b1716fa9983b0662773fea92eb8847edb65557c
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-wordified-and-comments-removed
that referenced
this pull request
Oct 1, 2019
…nishearth <!-- Please describe your changes on the following line: --> servo/rust-cssparser#123 In particular, `match_ignore_ascii_case` now supports the full `match` syntax. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fbfcfc2dbe838ef011f14a863003a575078f455f UltraBlame original commit: 7b1716fa9983b0662773fea92eb8847edb65557c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#122 introduced a procedural component to some
macro_rules
macros by abusingderive
on a dummy type declaration. (Customderive
is available on stable Rust 1.15, but functional procedural macros are not.) It used an attribute to pass data to the procedural macro, but this data is limited to string literals in Rust 1.15.We can improve on this with an idea from @dtolnay:
Instead of a custom attribute, we use an enum with an explicit discriminant (because that’s the only case where a type definition can contain a (const) expression), together with accessing the first field of a literal tuple to ignore other fields.
Instead of just string literals, we can accept arbitrary tokens that
stringify!
will later be expanded into something parseable in a const expression context. (stringify!
doesn’t help in attributes because it is not yet expanded by the time anything other than string literals is rejected.)The details of this hack are hidden away into a new crate, called
procedural-masquerade
.This enables concrete benefits for users of cssparser:
match_ignore_ascii_case!
now supports the full syntax ofmatch
expressions, including alternativespattern | other_pattern
, bindingsname @ pattern
, and guardspattern if condition
.asci_case_insensitive_phf_map!
are now given literally instead of as string literals containing Rust syntax.This change is