Skip to content

Commit e716a7b

Browse files
committed
feat: rust enum variants including decorators
1 parent dcb1264 commit e716a7b

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

.github/workflows/unix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
git commit -m "cd: increment version.py; update readme [skip ci]"
8787
git push https://github.com/bionicles/tree_plus.git
8888
- name: Publish to PyPI
89-
uses: pypa/[email protected].2
89+
uses: pypa/[email protected].4
9090
# with:
9191
# user: __token__
9292
# password: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ absurdly-huge-jsonl:
3232
python tests/build_absurdly_huge_jsonl.py
3333

3434
# TESTS
35-
test: test-sequential test-tp-dotdot test-e2e test-cli test-programs test-deploy
35+
test: test-more-languages test-sequential test-tp-dotdot test-e2e test-cli test-programs test-deploy
3636

3737
N_WORKERS=12
3838
# parallel unit tests (for dev rig)

tests/more_languages/group4/rust_test.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ fn at_beginning<'a>(&'a str) {
33
}
44

55
// rust_test.rs
6-
enum Days {
6+
#[derive(Default)]
7+
pub enum Days<E: EdgeCase> {
8+
#[default]
79
Sun,
810
Mon,
11+
#[error("edge case {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)]
912
Tue,
1013
Wed,
11-
Thu,
12-
Fri,
13-
Sat,
14+
Thu(i16, bool),
15+
Fri { day: u8 },
16+
Sat {
17+
urday: String,
18+
edge_case: E,
19+
},
1420
}
1521

1622
struct Point {

tests/test_more_language_units.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,20 @@ def test_more_languages_group3(file: str, expected: List[str]):
12221222
"tests/more_languages/group4/rust_test.rs",
12231223
[
12241224
"fn at_beginning<'a>(&'a str)",
1225-
"enum Days",
1225+
"""pub enum Days<E: EdgeCase> {
1226+
#[default]
1227+
Sun,
1228+
Mon,
1229+
#[error("edge case {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)]
1230+
Tue,
1231+
Wed,
1232+
Thu(i16, bool),
1233+
Fri { day: u8 },
1234+
Sat {
1235+
urday: String,
1236+
edge_case: E,
1237+
},
1238+
}""",
12261239
"struct Point",
12271240
"impl Point",
12281241
" fn get_origin() -> Point",

tree_plus_src/parse_file.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,10 @@ def parse_rs(content: str, *, timeout: float = DEFAULT_REGEX_TIMEOUT) -> List[st
10471047
r"^(?P<function>\s*(?P<maybe_pub>pub\s+?)?(?P<maybe_async_or_const>(?:async|const)\s+)?(?P<fn>fn)\s+(?P<fn_name>\w+)(?P<generics><[^>]*?>)?(?P<argument_start>\()(?P<arguments>[&\w,':()<>${}\/\s]+?)?(?P<argument_end>\))[\s\S]*?)(?P<end>(?:;\s)|(?:{))|"
10481048
# structs and impls with generics
10491049
r"\n(?P<struct_impl>(?: *((?:pub\s+)?struct)|impl)[^{;]*?) ?[{;]|"
1050-
# trait, enum, or mod
1051-
r"\n(?P<trait_enum_mod> *(?:pub\s+)?(trait|enum|mod)\s+\w*(<[^{]*>)?)|"
1050+
# enum with variants
1051+
r"^\s*(?P<enum>(?P<visibility>pub\s+?)?enum (?P<enum_name>\w+)(?P<maybe_generics><[^>]*?>)? {(?P<variant>(?P<maybe_decorator>\s+#\[.*\]+?)?\s+(?P<variant_name>\w+)(?P<maybe_data>(?P<tuple_variant>\([\s\S]+?\))|(?P<struct_variant> \{[^}]+\}))?,)*\s\})\s|"
1052+
# trait, or mod
1053+
r"\n(?P<trait_mod> *(?:pub\s+)?(trait|mod)\s+\w*(<[^{]*>)?)|"
10521054
# macro
10531055
r"\n(?P<macro>((#\[macro_export\]\n)?macro_rules!\s+[a-z_][a-z_0-9]*))",
10541056
regex.MULTILINE,
@@ -1066,8 +1068,10 @@ def parse_rs(content: str, *, timeout: float = DEFAULT_REGEX_TIMEOUT) -> List[st
10661068
elif groups.get("struct_impl"):
10671069
component = groups["struct_impl"].rstrip()
10681070
# trait, enum, mod
1069-
elif groups.get("trait_enum_mod"):
1070-
component = groups["trait_enum_mod"]
1071+
elif groups.get("enum"):
1072+
component = groups["enum"]
1073+
elif groups.get("trait_mod"):
1074+
component = groups["trait_mod"]
10711075
# macro
10721076
elif groups.get("macro"):
10731077
component = groups["macro"]

0 commit comments

Comments
 (0)