Giter VIP home page Giter VIP logo

command-macros's People

Contributors

krdln avatar ksxgithub 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

Watchers

 avatar  avatar

command-macros's Issues

Reimplement the procedural command! macro using macros 2.0

The current command! macro was implemented using rustc's internals, which wasn't pleasant to maintain (also, it was hard to make it work on multiple versions of nightly). Therefore, I decided to drop the support for it.

That macro should be reimplemented using procedural macros 2.0. It's still a nightly feature, but it's a more stable target, and hopefully will stabilize in a near future.

  • Investigate if it's possible to attach custom spans to macro-created elements (it's not needed to have a workable macro, but it improves error message)
  • Do it.

Broken on rustc 1.26.0-nightly (2789b067d 2018-03-06) :(

I can't compile the plugin:

error[E0555]: malformed feature attribute, expected #![feature(...)]
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/lib.rs:245:5
    |
245 | /     feature(
246 | |         plugin_registrar,
247 | |         rustc_private,
248 | |         quote,
249 | |     ),
250 | | )]
    | |_^

error: cannot find macro `quote_stmt!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:144:37
    |
144 |     let mut stmts: Vec<Stmt> = vec![quote_stmt!(cx, let mut _cmd = $cmd_expr).unwrap()];
    |                                     ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:147:45
    |
147 |     Ok(cx.block_with_expr(span, stmts, Some(quote_expr!(cx, _cmd))))
    |                                             ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:153:20
    |
153 |     let cmd_expr = quote_expr!(cx, _cmd);
    |                    ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:187:43
    |
187 |                     Condition::Bool(e) => quote_expr!(cx, if $e $then else $els),
    |                                           ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:188:47
    |
188 |                     Condition::IfLet(p, e) => quote_expr!(cx, if let $p = $e $then else $els)
    |                                               ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:193:17
    |
193 |                 quote_expr!(cx, for $pat in $expr $body)
    |                 ^^^^^^^^^^

error: cannot find macro `quote_expr!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:202:18
    |
202 |     let s_expr = quote_expr!(cx, s);
    |                  ^^^^^^^^^^

error: cannot find macro `quote_stmt!` in this scope
   --> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:212:34
    |
212 |             let mut stmts = vec![quote_stmt!(cx, let mut s = ::std::ffi::OsString::new()).unwrap()];
    |                                  ^^^^^^^^^^

error: aborting due to 9 previous errors

If you want more information on this error, try using "rustc --explain E0555"
error: Could not compile `command-macros`.

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

The simpler cmd! macro still works thankfully.

Macro for constructing `duct::Expression`

This is something I've found myself wanting as I consider migrating a project from using std::process::Command to using duct::Expression. Unfortunately there's no easy way to convert between the two types, so the command! macro can't be used.

I've made an initial implementation & tests using proc_macro; all the functionality of the command! macro is intact, with the following changes:

  • {x} takes a duct::Expression
  • (x) takes Into<OsString>, as required by Expression, rather than AsRef<OsString>; as a result, the argument is moved instead of referenced
  • [x] takes IntoIterator<Item=impl Info<OsStr>> rather than IntoIterator<Item=impl AsRef<OsStr>>

A slight rough edge is the error message if the user doesn't have the duct crate in dependencies (or it's been renamed) - this gives the error message "could not find duct in {{root}}". I'm not sure if it's possible to replace that message.

I'd be happy to update documentation and put up a PR if this would be wanted.

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.