mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 17:11:02 +00:00
Initial support for syntex
This commit is contained in:
@@ -5,8 +5,20 @@ authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
|||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros to auto-generate implementations for the serde framework"
|
description = "Macros to auto-generate implementations for the serde framework"
|
||||||
repository = "https://github.com/erickt/rust-serde"
|
repository = "https://github.com/erickt/rust-serde"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["with-syntex"]
|
||||||
|
nightly = ["quasi_macros"]
|
||||||
|
with-syntex = ["quasi/with-syntex", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
quasi_codegen = { verision = "*", optional = true }
|
||||||
|
syntex = { version = "*", optional = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aster = "*"
|
aster = { version = "*", default-features = false }
|
||||||
quasi = "*"
|
quasi = { verision = "*", default-features = false }
|
||||||
quasi_macros = "*"
|
quasi_macros = { version = "*", optional = true }
|
||||||
|
syntex = { version = "*", optional = true }
|
||||||
|
syntex_syntax = { version = "*", optional = true }
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
mod inner {
|
||||||
|
extern crate syntex;
|
||||||
|
extern crate quasi_codegen;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
let mut registry = syntex::Registry::new();
|
||||||
|
quasi_codegen::register(&mut registry);
|
||||||
|
|
||||||
|
let src = Path::new("src/lib.rs.in");
|
||||||
|
let dst = Path::new(&out_dir).join("lib.rs");
|
||||||
|
|
||||||
|
registry.expand("", &src, &dst).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
|
mod inner {
|
||||||
|
pub fn main() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
inner::main();
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ use syntax::attr;
|
|||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use super::attr::FieldAttrs;
|
use attr::FieldAttrs;
|
||||||
|
|
||||||
enum Rename<'a> {
|
enum Rename<'a> {
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -1,16 +1,65 @@
|
|||||||
#![feature(custom_derive, plugin, rustc_private, unboxed_closures)]
|
#![cfg_attr(not(feature = "with-syntex"), feature(rustc_private, plugin))]
|
||||||
#![plugin(quasi_macros)]
|
#![cfg_attr(not(feature = "with-syntex"), plugin(quasi_macros))]
|
||||||
|
|
||||||
extern crate aster;
|
extern crate aster;
|
||||||
extern crate quasi;
|
extern crate quasi;
|
||||||
extern crate rustc;
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
extern crate syntex;
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
extern crate syntex_syntax as syntax;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
mod attr;
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
mod de;
|
extern crate rustc;
|
||||||
mod field;
|
|
||||||
mod ser;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/lib.rs"));
|
||||||
|
|
||||||
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
|
include!("lib.rs.in");
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
pub fn register(reg: &mut syntex::Registry) {
|
||||||
|
use syntax::{ast, fold};
|
||||||
|
|
||||||
|
reg.add_attr("feature(custom_derive)");
|
||||||
|
reg.add_attr("feature(custom_attribute)");
|
||||||
|
|
||||||
|
reg.add_decorator("derive_Serialize", ser::expand_derive_serialize);
|
||||||
|
reg.add_decorator("derive_Deserialize", de::expand_derive_deserialize);
|
||||||
|
|
||||||
|
reg.add_post_expansion_pass(strip_attributes);
|
||||||
|
|
||||||
|
/// Strip the serde attributes from the crate.
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
fn strip_attributes(krate: ast::Crate) -> ast::Crate {
|
||||||
|
/// Helper folder that strips the serde attributes after the extensions have been expanded.
|
||||||
|
struct StripAttributeFolder;
|
||||||
|
|
||||||
|
impl fold::Folder for StripAttributeFolder {
|
||||||
|
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
|
||||||
|
match attr.node.value.node {
|
||||||
|
ast::MetaList(ref n, _) if n == &"serde" => { return None; }
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||||
|
fold::noop_fold_mac(mac, self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fold::Folder::fold_crate(&mut StripAttributeFolder, krate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
pub fn register(reg: &mut rustc::plugin::Registry) {
|
pub fn register(reg: &mut rustc::plugin::Registry) {
|
||||||
reg.register_syntax_extension(
|
reg.register_syntax_extension(
|
||||||
syntax::parse::token::intern("derive_Serialize"),
|
syntax::parse::token::intern("derive_Serialize"),
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
mod attr;
|
||||||
|
mod de;
|
||||||
|
mod field;
|
||||||
|
mod ser;
|
||||||
@@ -11,4 +11,9 @@ name = "serde_macros"
|
|||||||
plugin = true
|
plugin = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_codegen = { version = "*", path = "../serde_codegen" }
|
serde_codegen = { version = "*", path = "../serde_codegen", default-features = false, features = ["nightly"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
num = "*"
|
||||||
|
rustc-serialize = "*"
|
||||||
|
serde = { version = "*", path = "../serde" }
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#![feature(custom_attribute, custom_derive, plugin, test)]
|
||||||
|
#![plugin(serde_macros)]
|
||||||
|
|
||||||
|
extern crate num;
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
extern crate serde;
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
include!("../../serde_tests/benches/bench.rs.in");
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#![feature(test, custom_attribute, custom_derive, plugin)]
|
||||||
|
#![plugin(serde_macros)]
|
||||||
|
|
||||||
|
extern crate serde;
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
include!("../../serde_tests/tests/test.rs.in");
|
||||||
@@ -8,14 +8,18 @@ repository = "https://github.com/serde-rs/serde"
|
|||||||
documentation = "http://serde-rs.github.io/serde/serde"
|
documentation = "http://serde-rs.github.io/serde/serde"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["serialization"]
|
keywords = ["serialization"]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[build-dependencies]
|
||||||
num = "*"
|
syntex = { version = "*", optional = true }
|
||||||
|
syntex_syntax = { version = "*" }
|
||||||
|
serde_codegen = { version = "*", path = "../serde_codegen", features = ["with-syntex"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
num = "*"
|
||||||
rustc-serialize = "*"
|
rustc-serialize = "*"
|
||||||
serde = { version = "*", path = "../serde" }
|
serde = { version = "*", path = "../serde" }
|
||||||
serde_macros = { version = "*", path = "../serde_macros" }
|
syntex = "*"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "test"
|
name = "test"
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin, test)]
|
#![feature(test)]
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
|
extern crate num;
|
||||||
|
extern crate rustc_serialize;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
mod syntax {
|
include!(concat!(env!("OUT_DIR"), "/bench.rs"));
|
||||||
include!("bench.rs.in");
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
extern crate syntex;
|
||||||
|
extern crate serde_codegen;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
|
||||||
|
for &(src, dst) in &[
|
||||||
|
("tests/test.rs.in", "test.rs"),
|
||||||
|
("benches/bench.rs.in", "bench.rs"),
|
||||||
|
] {
|
||||||
|
let src = Path::new(src);
|
||||||
|
let dst = Path::new(&out_dir).join(dst);
|
||||||
|
|
||||||
|
let mut registry = syntex::Registry::new();
|
||||||
|
|
||||||
|
serde_codegen::register(&mut registry);
|
||||||
|
registry.expand("", &src, &dst).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin, test)]
|
#![feature(test)]
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
include!("test.rs.in");
|
include!(concat!(env!("OUT_DIR"), "/test.rs"));
|
||||||
|
|||||||
Reference in New Issue
Block a user