Skip to content

Commit 7107870

Browse files
committed
Add an easy way to toggle the procedural macro, so it's easier to test both behaviors.
1 parent cb8a26a commit 7107870

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ quote = "0.3"
3131
serde-serialization = [ "serde" ]
3232
heap_size = [ "heapsize" ]
3333
bench = []
34+
dummy_match_byte = []

build.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@ extern crate syn;
55
use std::env;
66
use std::path::Path;
77

8+
9+
#[cfg(feature = "dummy_match_byte")]
10+
mod codegen {
11+
use std::path::Path;
12+
pub fn main(_: &Path) {}
13+
}
14+
15+
#[cfg(not(feature = "dummy_match_byte"))]
816
#[path = "src/macros/mod.rs"]
917
mod macros;
1018

19+
#[cfg(not(feature = "dummy_match_byte"))]
20+
mod codegen {
21+
use macros;
22+
use std::env;
23+
use std::path::Path;
24+
25+
pub fn main(tokenizer_rs: &Path) {
26+
macros::match_byte::expand(tokenizer_rs,
27+
&Path::new(&env::var("OUT_DIR").unwrap()).join("tokenizer.rs"));
28+
29+
}
30+
}
31+
1132
fn main() {
1233
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
13-
1434
let tokenizer_rs = Path::new(&manifest_dir).join("src/tokenizer.rs");
15-
macros::match_byte::expand(&tokenizer_rs,
16-
&Path::new(&env::var("OUT_DIR").unwrap()).join("tokenizer.rs"));
17-
18-
println!("cargo:rerun-if-changed={}", tokenizer_rs.display());
35+
codegen::main(&tokenizer_rs);
36+
println!("cargo:rerun-if-changed={}", tokenizer_rs.display());
1937
}

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ macro_rules! match_ignore_ascii_case {
137137
}
138138

139139
mod rules_and_declarations;
140+
141+
#[cfg(feature = "dummy_match_byte")]
142+
macro_rules! match_byte {
143+
($value:expr, $($rest:tt)* ) => {
144+
match $value {
145+
$(
146+
$rest
147+
)+
148+
}
149+
};
150+
}
151+
152+
#[cfg(feature = "dummy_match_byte")]
153+
mod tokenizer;
154+
155+
#[cfg(not(feature = "dummy_match_byte"))]
140156
mod tokenizer {
141157
include!(concat!(env!("OUT_DIR"), "/tokenizer.rs"));
142158
}

0 commit comments

Comments
 (0)