teddriggs / syn-inline-mod Goto Github PK
View Code? Open in Web Editor NEWTool to inline module contents into syn::File instances
License: MIT License
Tool to inline module contents into syn::File instances
License: MIT License
We're only bringing items
over, and should be bringing items
and attrs
.
This seems highly desirable for cargo crev
's use case.
From each syn::ItemMod that gets parsed, you can find the Span of the semicolon and use Span::start from proc-macro2's "span-locations" feature to figure out the input file line and column of the semicolon. Then you can replace that semicolon character in the original source string with a set of braces containing an indented content of the child module. The final output would be a string of source code rather than syn::File, which the caller can parse to syn::File if they want.
Looks like this code currently panics if there's an error while the file's being opened, read or parsed: https://github.com/TedDriggs/syn-inline-mod/blob/master/src/resolver.rs#L22-L27
As a library, syn-inline-mod
should probably return errors for consumers to process as they wish instead.
= note: expected type `&syn::file::File` (struct `syn::file::File`)
found type `&syn::file::File` (struct `syn::file::File`)
note: Perhaps two different versions of crate `syn` are being used?
--> src/main.rs:38:39
|
38 | let functions = get_syn_functions(&syntax);
This is a snippet from the error i get when I want to get an entire syn-parsed file using syn-inline-mod.
Maybe this crate could be split into just doing the inline part and returning an entire inlined source code. Allowing one to use their own version of syn with the feature flags that I need.
And having the parsing part separate?
rust-reduce took a dependency on this crate and I'm running into an error running it jethrogb/rust-reduce#5. I think upgrading the dependencies would help.
Lines 12 to 17 in 3704707
The latest are:
https://github.com/dtolnay/syn 1.0.4
https://github.com/alexcrichton/proc-macro2 1.0.6
https://github.com/dtolnay/quote 1.0.2
Thanks again for releasing version 0.4!
Looks like there's one more thing I need, which is the ability to report errors in the parsed syn::File
. For that the main thing I need is to be able to map span data back to the files it came from.
How does this design sound?
#[syn_inline_mod_source_path = "..."]
. Readers can then look through the attributes (add an API to syn-inline-mod
to do so for convenience).InlinerBuilder
which configures whether these annotations should be inserted (default false
).I'm planning to publish a crate that ties together syn-inline-mod
and codespan-reporting
so that tools can report custom errors.
I am trying to expand Rust code to other languages using Rust_swig
, which is using syn
.
From what I understand syn-inline-mod
can parse Rust code, and it understands #cfg, which syn lacks (dtolnay/syn#588). I am trying to use syn-inline-mod in Rust swig, but I don't fully understand it. Can you include some guide/ example code on how to use it?
Consider the following example from dtolnay/request-for-implementation#6
r#"
#[cfg(feature = "m1")]
mod m1;
#[cfg_attr(feature = "m2", path = "m2.rs")]
#[cfg_attr(not(feature = "m2"), path = "empty.rs")]
mod placeholder;
According to that ticket, this should expand to two declarations of mod placeholder
, with the cfg_attr
being converted to a normal cfg
attribute.
I'm not sure this is worth the complexity it creates. Consider the following case:
#[cfg_attr(feature = "foo", path = "m2")]
#[cfg_attr(not(feature = "foo"), path = "m3")]
mod outer {
#[cfg_attr(feature = "foo", path = "baz.rs")]
#[cfg_attr(not(feature = "foo"), path = "bar.rs")]
mod placeholder;
}
We'd need to emit outer
twice, with placeholder
twice inside.
I can't tell from the readme and current documentation what this crate does and which edge cases it can/cannot handle.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.