Coder Social home page Coder Social logo

Comments (5)

dtolnay avatar dtolnay commented on July 16, 2024

Syn itself compiles fine on stable, in fact serde_codegen depends on it on stable. Here is the relevant code.

  • Use syntex to register a custom derive
  • Receive a syntex AST in your registered function
  • Use pprust to print it to a string
  • Parse it to a syn AST
  • Expand it using the same codepath that proc_macro uses
  • Print the expanded syn AST to a string
  • Create a syntex parse session and parse it
  • Return the expanded syntex AST

There are a few missing pieces before it can be used without syntex but I have been making steady progress on those and expect to have it ready in the next week or two. The biggest blocker was being able to parse the full Rust syntax other than just structs and enums. That is largely done, for example this 6000 line file copied from the rustc source code can be parsed and printed back such that the original and the printed one are parsed identically by syntex.

If you have time to help out, the remaining missing pieces in order of importance are:

  • Porting over syntex's custom-derive registry and derive-finding code
  • Implementing a workaround for this parsing ambiguity in Rust
  • Integrating an optional dependency on a pretty-printer (probably syntex)
  • Floating point literals #10
  • Hexadecimal, octal, binary literals and literals containing underscores #34

The pretty-printer is because debugging will be much easier if your build.rs produces formatted code rather than a single massive line. I don't want to be in the business of maintaining a pretty printer myself, so we need to use a dependency on an existing one that can be disabled once things work.

from syn.

dtolnay avatar dtolnay commented on July 16, 2024

I implemented the biggest missing piece in #55. I will try to make it through the remaining items quickly.

let mut registry = Registry::new();
registry.add_derive("Serialize", expand_serialize);
registry.add_derive("Deserialize", expand_deserialize);
registry.expand_file(src, dst).unwrap();

fn expand_serialize(input: MacroInput) -> Result<Expanded, String> { /* ... */ }
fn expand_deserialize(input: MacroInput) -> Result<Expanded, String> { /* ... */ }

from syn.

dtolnay avatar dtolnay commented on July 16, 2024

All the pieces have been implemented. I need to write documentation and example code and cut a release.

from syn.

emk avatar emk commented on July 16, 2024

This is just fantastic! I have a couple of crates that will benefit from this.

from syn.

dtolnay avatar dtolnay commented on July 16, 2024

I released 0.10.0 with a custom-derive registry that is able to expand custom derives on stable Rust.

from syn.

Related Issues (20)

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.