Skip to content

Commit 7879937

Browse files
author
andrew
committed
Reorg, rewrite, bump deps, enums
1 parent 088994d commit 7879937

File tree

9 files changed

+974
-368
lines changed

9 files changed

+974
-368
lines changed

Cargo.toml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
[package]
2-
name = "structre"
3-
version = "0.0.4"
1+
[workspace]
2+
resolver = "2"
3+
members = ["crates/structre", "crates/structre_proc_macros"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
47
edition = "2021"
58
license = "ISC"
6-
description = "Static-checked parsing of regexes into structs"
7-
homepage = "https://github.com/andrewbaxter/structre"
89
repository = "https://github.com/andrewbaxter/structre"
910
readme = "readme.md"
10-
11-
[workspace]
12-
members = ["src/proc_macros"]
13-
14-
[features]
15-
default = ["unicode"]
16-
unicode = ["structre_proc_macros/unicode", "regex/unicode"]
17-
18-
[dependencies]
19-
regex = { version = "1.7.0", default-features = false, features = ["std"] }
20-
structre_proc_macros = { path = "src/proc_macros", version = "0.0.3" }

crates/structre/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "structre"
3+
description = "Static-checked parsing of regexes into structs"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
readme.workspace = true
9+
10+
[features]
11+
default = ["unicode"]
12+
unicode = ["structre_proc_macros/unicode", "regex/unicode"]
13+
14+
[dependencies]
15+
regex = { version = "1", default-features = false, features = ["std"] }
16+
static_init = "1"
17+
structre_proc_macros = { path = "../structre_proc_macros" }
File renamed without changes.

tests/test.rs renamed to crates/structre/tests/test.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use structre::structre;
1+
use {
2+
structre::structre,
3+
std::str::FromStr,
4+
};
25

36
#[cfg(feature = "unicode")]
47
#[test]
58
fn match_() {
69
#[structre("(a)(44)")]
710
struct Parsed(String, u32);
811

9-
let pre = Parsed::parser();
10-
let v = pre.parse("a44").unwrap();
12+
let v = Parsed::from_str("a44").unwrap();
1113
assert_eq!(v.0, "a");
1214
assert_eq!(v.1, 44);
1315
}
@@ -21,8 +23,7 @@ fn named() {
2123
b: u32,
2224
}
2325

24-
let pre = Parsed::parser();
25-
let v = pre.parse("a44").unwrap();
26+
let v = Parsed::from_str("a44").unwrap();
2627
assert_eq!(v.a, "a");
2728
assert_eq!(v.b, 44);
2829
}
@@ -33,8 +34,7 @@ fn uncapture() {
3334
#[structre("(?:(a))")]
3435
struct Parsed(String);
3536

36-
let pre = Parsed::parser();
37-
let v = pre.parse("a").unwrap();
37+
let v = Parsed::from_str("a").unwrap();
3838
assert_eq!(v.0, "a");
3939
}
4040

@@ -46,7 +46,22 @@ fn uncapture_named() {
4646
a: String,
4747
}
4848

49-
let pre = Parsed::parser();
50-
let v = pre.parse("a").unwrap();
49+
let v = Parsed::from_str("a").unwrap();
5150
assert_eq!(v.a, "a");
5251
}
52+
53+
#[cfg(feature = "unicode")]
54+
#[test]
55+
fn test_enum() {
56+
#[structre("(?P<A>a)|(?P<b>b)")]
57+
#[derive(PartialEq, Eq, Debug)]
58+
enum Parsed {
59+
A(String),
60+
B {
61+
b: String,
62+
},
63+
}
64+
65+
let v = Parsed::from_str("a").unwrap();
66+
assert_eq!(v, Parsed::A("a".to_string()));
67+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "structre_proc_macros"
3+
description = "Static-checked parsing of regexes into structs (helper crate)"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
readme.workspace = true
9+
10+
[lib]
11+
proc-macro = true
12+
path = "mod.rs"
13+
14+
[features]
15+
default = ["unicode"]
16+
unicode = []
17+
18+
[dependencies]
19+
flowcontrol = "0.2"
20+
litrs = "0.4"
21+
proc-macro2 = "1"
22+
quote = "1"
23+
regex-syntax = "0.8"
24+
syn = "2"
25+
26+
[dev-dependencies]
27+
genemichaels = "0.5.0-pre1"

0 commit comments

Comments
 (0)