quote_expr macro: embed Ident using special encoding that retains hygiene state. #16477

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@pnkfelix
Member

quote_expr macro: embed Ident using special encoding that retains hygiene state.

Fix #15750, #15962

pnkfelix added some commits Aug 1, 2014
@pnkfelix pnkfelix quote_expr macro: embed Ident using special encoding that preserves h…
…ygiene.

This adds support to `quote_expr!` and friends for round-trip hygienic
preservation of Ident.

Here are the pieces of the puzzle:

* adding a method for encoding Ident for re-reading into token tree.

* Support for reading such encoded Idents in the lexer.  Note that one
  must peek ahead for MOD_SEP after scan_embedded_hygienic_ident.

* To ensure that encoded Idents are only read when we are in the midst
  of expanding a `quote_expr` or similar, added a
  `read_embedded_ident` flag on `StringReader`.

* pprust support for encoding Ident's as (uint,uint) pairs (for hygiene).
c3ce245
@pnkfelix pnkfelix rustc lexer: regression tests for embedded Idents.
I chose to make two of them because I wanted something close to an
"end-to-end" test (*), but at the same time I wanted a test that
would run on Windows (**).

(*) The run-make test serves as the end-to-end: It constructs an input
that is trying to subvert the hack and we are going to check that it
fails in the attempt).

(**) The compile-fail-fulldeps test serves as a more narrow test that
will be tested on all platforms.  It also attempts to subvert the
hack, testing that when you use `new_parser_from_tts`, the resulting
parser does not support reading embedded Idents.
9434920
@pnkfelix
Member

r? anyone, perhaps @huonw

@brson
Contributor
brson commented Aug 13, 2014

Awesome hack! Thanks for working this out, @pnkfelix.

@brson
brson commented on 9434920 Aug 14, 2014

r+ p=1

Contributor
bors replied Aug 14, 2014

saw approval from brson
at pnkfelix@9434920

Contributor
bors replied Aug 14, 2014

merging pnkfelix/rust/fsk-quotstx = 9434920 into auto

Contributor
bors replied Aug 14, 2014

pnkfelix/rust/fsk-quotstx = 9434920 merged ok, testing candidate = aa98b25

Contributor
bors replied Aug 14, 2014

fast-forwarding master to auto = aa98b25

@bors bors added a commit that referenced this pull request Aug 14, 2014
@bors bors auto merge of #16477 : pnkfelix/rust/fsk-quotstx, r=brson
quote_expr macro: embed Ident using special encoding that retains hygiene state.

Fix #15750, #15962
aa98b25
@bors bors closed this Aug 14, 2014
@pnkfelix
Member

I realized last night that perhaps the most important test was not included in the PR above: namely, a run-pass test of a use of quote_expr! itself in a procedural macro, perhaps the form of the one posted on #15750. (The PR above just added compile-fail tests to ensure that the hack did not leak outside of quote_expr!.) I will put up a PR with a run-pass test shortly.

@pnkfelix pnkfelix added a commit to pnkfelix/rust that referenced this pull request Aug 14, 2014
@pnkfelix pnkfelix Followup to PR #16477: a run-pass regression test for Issue #15750. 43c326e
@bors bors added a commit that referenced this pull request Aug 15, 2014
@bors bors auto merge of #16494 : pnkfelix/rust/fsk-quotstx-followup, r=alexcric…
…hton

Followup to PR #16477: a run-pass regression test for Issue #15750.
729ea05
@bors bors added a commit that referenced this pull request Aug 15, 2014
@bors bors auto merge of #16494 : pnkfelix/rust/fsk-quotstx-followup, r=alexcric…
…hton

Followup to PR #16477: a run-pass regression test for Issue #15750.
1d12b6d
@larsbergstrom
Contributor

@pnkfelix Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment