Giter Club home page Giter Club logo

interpolate_idents's Introduction

interpolate_idents

Deprecated

This crate has been officially deprecated.

Because of the introduction of stable procedural macro support in Rust 1.30.0, it is now possible to accomplish what this crate set out to accomplish using entirely stable code. Please try @dtolnay's paste crate to see if it can fulfill all of your current use cases. paste can be used in stable production environments and is not nearly as prone to breakage between Rust versions.

Summary

Travis-CI Status

Warning! This crate uses a procedural macro (known today as a compiler plugin) and can only be used with Rust's nightly distribution.

You cannot currently define a struct, enum, function, or field using concat_idents! due to the way macros are parsed by the Rust compiler. This will hopefully change in the future, but interpolate_idents! sloppily solves a side effect of the currently lacking macro system today.

#![feature(plugin)]
#![plugin(interpolate_idents)]

macro_rules! make_fn {
    ($x:ident) => ( interpolate_idents! {
        fn [my_ $x _fn]() -> u32 { 1000 }
    } )
}

Now make_fn!(favorite); is equivalent to fn my_favorite_fn() -> u32 { 1000 }.

In short, surround multiple space-separated identifiers (or macro identifer variables) with square brackets to concatenate the identifiers. Check tests/tests.rs for another example.

This plugin was quickly hacked together. It is likely not performant and most certainly not readable.

Crate upkeep

I'm not actively developing on nightly, so I haven't been using this plugin too often. I understand that libsyntax is a fickle beast, so please file an issue or PR if interpolate_idents fails to compile on the latest nightly!

interpolate_idents's People

Contributors

adriandanis avatar aidanhs avatar bert-proesmans avatar dgrunwald avatar gnzlbg avatar jimmantooth avatar joshlf avatar lu-zero avatar mattico avatar mb1986 avatar mneumann avatar rajatgoel avatar skylerlipthay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

interpolate_idents's Issues

Does not build on nightly

Hi, tried to compile this today, and it fails with:

error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> /home/afonso/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.6/src/parser_any_macro.rs:86:48
   |
86 |                 _ => ret.push(panictry!(parser.parse_impl_item()))
   |                                                ^^^^^^^^^^^^^^^ expected 1 parameter

error: aborting due to previous error

error: Could not compile `interpolate_idents`.

To learn more, run the command again with --verbose.

Doesn't compile on latest nightly

Well, that was fast.
rustc 1.17.0-nightly (0aeb9c129 2017-03-15)

   Compiling interpolate_idents v0.1.5
error[E0308]: mismatched types
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.5/src/lib.rs:60:41
   |
60 |                     match concat_idents(&d.tts, d.delim) {
   |                                         ^^^^^^ expected struct `std::vec::Vec`, found struct `syntax::tokenstream::ThinTokenStream`
   |
   = note: expected type `&std::vec::Vec<syntax::tokenstream::TokenTree>`
              found type `&syntax::tokenstream::ThinTokenStream`

error: type `syntax::tokenstream::ThinTokenStream` cannot be dereferenced
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.5/src/lib.rs:65:47
   |
65 |                                 tts: map_tts(&*d.tts),
   |                                               ^^^^^^

error[E0308]: mismatched types
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.5/src/lib.rs:65:38
   |
65 |                                 tts: map_tts(&*d.tts),
   |                                      ^^^^^^^^^^^^^^^^ expected struct `syntax::tokenstream::ThinTokenStream`, found struct `std::vec::Vec`
   |
   = note: expected type `syntax::tokenstream::ThinTokenStream`
              found type `std::vec::Vec<syntax::tokenstream::TokenTree>`
   = help: here are some functions which might fulfill your needs:
           - .remove(...)
           - .swap_remove(...)

error[E0308]: mismatched types
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.5/src/lib.rs:63:61
   |
63 |                               TokenTree::Delimited(s.clone(), Rc::new(syntax::tokenstream::Delimited {
   |  _____________________________________________________________^ starting here...
64 | |                                 delim: d.delim,
65 | |                                 tts: map_tts(&*d.tts),
66 | |                             }))
   | |______________________________^ ...ending here: expected struct `syntax::tokenstream::Delimited`, found struct `std::rc::Rc`
   |
   = note: expected type `syntax::tokenstream::Delimited`
              found type `std::rc::Rc<syntax::tokenstream::Delimited>`

Last working version: 2017-03-04

Deprecated - please migrate to the paste crate

I don't really know how to easily reach those using interpolate_idents, but @dtolnay recently published paste: a crate that does the same thing that interpolate_idents does but uses a procedural macro and works in stable Rust 1.30.0 and up. That is, no more breakage due to rustc changes.

The syntax to use it is slightly different: paste uses [< and >] as delimiters instead of just [ and ], which means that one does not need to write [[ ]] anymore when indexing arrays. We have been happily using it in packed_simd for a week.

While interpolate_idents has served us very well for a very long time, maybe it is time to deprecate it. We could change the readme to point to the paste crate and upload one last version to crates.io to show this there as well. The next time the crate breaks, we could just leave it broken, and tell people to migrate.

An alternative would be to maybe the next time something breaks, just re-export the paste crate from interpolate-idents or something like that. But I don't think it is worth maintaining two crates here.

Compilation failure on nightly

Output

error[E0615]: attempted to take value of method `hi` on type `&mut syntax::codemap::Span`
  --> /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.7/src/lib.rs:34:56
   |
34 |                                 Some(ref mut s) => { s.hi = span.hi; },
   |                                                        ^^
   |
   = help: maybe a `()` to call it is missing?
error[E0615]: attempted to take value of method `hi` on type `&syntax::codemap::Span`
  --> /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.7/src/lib.rs:34:66
   |
34 |                                 Some(ref mut s) => { s.hi = span.hi; },
   |                                                                  ^^
   |
   = help: maybe a `()` to call it is missing?

Misc

$ rustc --version
rustc 1.22.0-nightly (6f87d20a7 2017-09-29)

Build errors with nightly?

Apologies if this is a non-error, I'm still learning to use the Rust development tools.

When I cargo build my project that uses interpolate_idents I see:

error[E0624]: method `span_err` is private  --> /foo/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.2.4/src/parser_any_macro.rs:54:20
   |
54 |             parser.span_err(span, &msg[..]);
   |

And

error[E0624]: method `parse_impl_item` is private  --> /foo/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.2.4/src/parser_any_macro.rs:86:48
   |
86 |                 _ => ret.push(panictry!(parser.parse_impl_item(&mut false)))
   |

With:

$ ~/.cargo/bin/cargo --version
cargo 1.28.0-nightly (e2348c2db 2018-06-07)

Broken on nightly

The crate has been broken since the 2018-11-05 nightly with:

$ cargo test
   Compiling interpolate_idents v0.2.8 (/home/travis/build/SkylerLipthay/interpolate_idents)
error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> src/parser_any_macro.rs:68:54
   |
68 |         let ret = panictry!(self.parser.borrow_mut().parse_pat());
   |                                                      ^^^^^^^^^ expected 1 parameter
error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> src/parser_any_macro.rs:68:54
   |
68 |         let ret = panictry!(self.parser.borrow_mut().parse_pat());
   |                                                      ^^^^^^^^^ expected 1 parameter
error: aborting due to previous error
For more information about this error, try `rustc --explain E0061`.
error: aborting due to previous error
For more information about this error, try `rustc --explain E0061`.
error: Could not compile `interpolate_idents`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `interpolate_idents`.

I'll prepare a fix. In the mean time, those running into this should give the paste crate a try - see this announcement: #45

Dependency issues

I have a crate epics-sys which should export a macro that uses interpolate_idents. Currently I get the following error when I compile a crate that depends on epics-sys:

error: cannot find macro `interpolate_idents!` in this scope
  --> <epics_register_function macros>:2:1
   |
1  | / ( $ func : ident , $ type : ty ) => (
2  | | interpolate_idents ! {
   | | ^^^^^^^^^^^^^^^^^^
3  | | # [ no_mangle ] pub extern "C" fn $ func ( precord : * mut $ type ) -> :: std
4  | | :: os :: raw :: c_long {
...  |
14 | | std :: os :: raw :: c_void = [ register_func_ $ func ] as * const :: std :: os
15 | | :: raw :: c_void ; } )
   | |______________________- in this expansion of `epics_register_function!`
   |
  ::: src/lib.rs
   |
31 |   epics_register_function!( mySubInit, subRecord);
   |   ------------------------------------------------ in this macro invocation

Am I doing something wrong or do I need to add:

#![feature(plugin)]
#![plugin(interpolate_idents)]

to crate that depends on my crate?

Could not find `small_vector` in `util`

--> /cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.2.5/src/parser_any_macro.rs:10:19
|
10 | use syntax::util::small_vector::SmallVector;
| ^^^^^^^^^^^^ Could not find small_vector in util
error: aborting due to previous error

Failing on nightly

interpolate_idents is failing on today's nightly. See, e.g., the error from this Travis build:

error[E0599]: no variant named `Underscore` found for type `syntax::parse::token::Token` in the current scope
  --> /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.2.2/src/lib.rs:39:52
   |
39 |                         TokenTree::Token(ref span, Token::Underscore) => {
   |                                                    ^^^^^^^^^^^^^^^^^ variant not found in `syntax::parse::token::Token`

Doesn't compile on latest nightly

rustc 1.17.0-nightly (b1e31766d 2017-03-03)

   Compiling interpolate_idents v0.1.4
error[E0422]: cannot find struct, variant or union type `SequenceRepetition` in module `syntax::tokenstream`
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.4/src/lib.rs:71:60
   |
71 |                     TokenTree::Sequence(s.clone(), Rc::new(syntax::tokenstream::SequenceRepetition {
   |                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `syntax::tokenstream`
   |
   = help: possible candidate is found in another module, you can import it into scope:
             `use syntax::ext::tt::quoted::SequenceRepetition;`

error: no associated item named `Sequence` found for type `syntax::tokenstream::TokenTree` in the current scope
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.4/src/lib.rs:70:18
   |
70 |                 &TokenTree::Sequence(ref s, ref d) => {
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: no associated item named `Sequence` found for type `syntax::tokenstream::TokenTree` in the current scope
  --> /home/yalter/.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.4/src/lib.rs:71:21
   |
71 |                     TokenTree::Sequence(s.clone(), Rc::new(syntax::tokenstream::SequenceRepetition {
   |                     ^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `interpolate_idents`.

error: #[feature] may not be used on the stable release channel [E0554]

Got this trying to compile project with dependency to cpython:

.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.2/src/lib.rs:1:1: 1:45 error: #[feature] may not be used on the stable release channel [E0554]
.cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.1.2/src/lib.rs:1 #![feature(plugin_registrar, rustc_private)]

rust stable:
rustc --version
rustc 1.11.0 (9b21dcd6a 2016-08-15)

cargo --version
cargo 0.12.0-nightly (6b98d1f 2016-07-04)

Problem with leading underscore

Hi
Thanks for this crate, its really saving my life right now :)

I have a problem though.
[_ $name bla bla] does not work, (single underscore)
[__ $name bla bla] does work. (double underscore)

Error when leading with single underscore is:

error: expected identifier, found `[`
   --> src/macros.rs:104:24
    |
104 |               pub static [_ $module _depend_on_ $mdepend]: ksys::mod_depend = ksys::mod_depend {
    |                          ^
    | 

Failure to compile on nightly 2018-01-27

I updated my nightly compiler this morning to "rustc 1.25.0-nightly (7d6e5b9da 2018-01-27)" and received the error below when trying to compile this library.
I cannot say with certainty that this compile error happens since this exact version because i only update once every few days.

error[E0277]: the trait bound `syntax::<unnamed>::FatalError: std::marker::Send` is not satisfied
  --> C:\Users\Bert\.cargo\registry\src\github.com-1ecc6299db9ec823\interpolate_idents-0.2.1\src\parser_any_macro.rs:61:19
   |
61 |         let ret = panictry!(self.parser.borrow_mut().parse_expr());
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                   |
   |                   `syntax::<unnamed>::FatalError` cannot be sent between threads safely
   |                   in this macro invocation
   |
   = help: the trait `std::marker::Send` is not implemented for `syntax::<unnamed>::FatalError`
   = note: required by `std::rt::begin_panic`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Edit: i wasn't complete with my information. The same error is thrown for each call to the panictry macro at lines 61, 66, 72, 86.

Stable compatibility

Like other crates have done (e.g. serde_codegen), perhaps provide the ability for someone to instead register the plugin and expand code in build.rs. It would only take a feature flag cfg checks sprinkled around to cut out the stable incompatible parts of this.

Set travis-ci with a daily cron-job to detect breakage

Would it be possible to set up travis-ci with a daily cron-job and email notification on breakage ?

The library is broken again:

--> /cargo/registry/src/github.com-1ecc6299db9ec823/interpolate_idents-0.2.7/src/parser_any_macro.rs:12:5
   |
12 |     OneVector,
   |     ^^^^^^^^^ no `OneVector` in the root

Collision with #[] type attributes

Hi

I have the following code inside a macro

        interpolate_idents! {
            #[link_section = concat!("set_", "$set")]
            #[used]
            pub static [__set_ $set _sym_ $sym]: &ksys::$type = &($sym);
        }

If I put the attributes outside of interpolate_idents {} they get discarded (not visible in expanded code).
Having them inside generates error:

error: expected `[`, found `used`
   --> src/macros.rs:33:15
    |
33  |               #[used]
    |                 ^^^^
    | 
   ::: src/lib.rs

Would it be easy to make it ignore attributes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.