44 breaking releases

Uses old Rust 2015

0.58.1 Feb 19, 2017
0.57.0 Jan 25, 2017
0.52.0 Nov 26, 2016
0.39.0 Jul 26, 2016
0.0.0 Dec 5, 2014

#31 in #expansion

Download history 1480/week @ 2023-12-20 1066/week @ 2023-12-27 1031/week @ 2024-01-03 1624/week @ 2024-01-10 1350/week @ 2024-01-17 1123/week @ 2024-01-24 1519/week @ 2024-01-31 1540/week @ 2024-02-07 1867/week @ 2024-02-14 1599/week @ 2024-02-21 1921/week @ 2024-02-28 1751/week @ 2024-03-06 1713/week @ 2024-03-13 2091/week @ 2024-03-20 2189/week @ 2024-03-27 1629/week @ 2024-04-03

7,980 downloads per month
This crate has lost popularity

MIT/Apache

16KB
362 lines

Syntex Code Generation Framework

Build Status Latest Version

syntex is a library that enables compile time syntax extension expansion. This allows users to use libraries like serde on stable Rust.

Configuring with Cargo

To create a package:

[package]
name = "hello_world_macros"
version = "0.2.0"
authors = [ "erick.tryzelaar@gmail.com" ]

[dependencies]
syntex = "*"
syntex_syntax = "*"

To use it:

Cargo.toml:

[package]
name = "hello_world"
version = "0.3.0"
authors = [ "erick.tryzelaar@gmail.com" ]
build = "build.rs"

[build-dependencies]
syntex = "*"

build.rs:

extern crate syntex;
extern crate hello_world_macros;

use std::env;
use std::path::Path;

fn main() {
    let mut registry = syntex::Registry::new();
    hello_world_macros::register(&mut registry);

    let src = Path::new("src/main.rs.in");
    let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("main.rs");

    registry.expand("hello_world", &src, &dst).unwrap();
}

src/main.rs:

// Include the real main
include!(concat!(env!("OUT_DIR"), "/main.rs"));

src/main.rs.in:

fn main() {
    let s = hello_world!();
    println!("{}", s);
}

Limitations

Unfortunately because there is no stable plugin support in Rust yet, there are some things that syntex cannot do:

  • The code generated by syntex reports errors in the generated file, not the source file.
  • Syntex macros cannot be embedded in macros it doesn't know about, like the builtin vec![], println!(...), and etc. This is because those macros may override the macro_name!(...) to mean something different.

Dependencies