Comments (5)
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.
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.
All the pieces have been implemented. I need to write documentation and example code and cut a release.
from syn.
This is just fantastic! I have a couple of crates that will benefit from this.
from syn.
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)
- syn::Path: Unknown literal value `()` HOT 2
- How to handle `AssignOp` from syn v1 to v2? HOT 1
- Custom punctuation containing `$` HOT 2
- Unsuccessful parsing of ExprRange consumes a token HOT 1
- Parse async closures trait bound syntax
- Parse mutable by-reference bindings syntax
- Parse postfix match syntax
- Parse for-await syntax
- Parse const trait bound syntax
- Stack overflow on a deeply nested chain of if-else expressions HOT 1
- Consider moving Visit, VisitMut, Fold traits to separate crate(s)
- Delete From impls of ast enums HOT 2
- Consider inserting invisible groups, rather than parens, when applying grouping for precedence
- Implement `Debug` for the AST nodes HOT 1
- parse_nested_meta don't work on attribute with multiple meta HOT 2
- Struct Literals in ExprLet HOT 1
- Parse `safe` items in extern blocks
- Parse precise capturing syntax HOT 1
- Scope when parsing delimited group content does not necessarily belong to the right Group token
- Parsing function using `parse` referencing enum fails HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syn.