Skip to content

Commit 5c8594d

Browse files
committed
wip
1 parent 69d50a7 commit 5c8594d

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

rust/rustell/src/decode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ pub fn expr<'src>() -> impl Parser<
99
Vec<Expr<'src>>,
1010
extra::Err<Rich<'src, char>>,
1111
> {
12-
expr_use()
13-
.or(expr_other())
12+
choice((expr_use(), expr_other()))
1413
.repeated()
1514
.collect::<Vec<_>>()
1615
}

rust/rustell/src/encode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn expr<'a>(
1010

1111
fn expr_one<'a>(ast: &'a Expr<'a>) -> IntoIter<&'a str> {
1212
match ast {
13+
Expr::Mod(x) => vec!["mod ", x, ";"].into_iter(),
1314
Expr::Use(x) => expr_use(true, x)
1415
.chain(once(";"))
1516
.collect::<Vec<_>>()

rust/rustell/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub use chumsky::prelude::Parser;
44

55
#[derive(Eq, PartialEq, Debug, Clone)]
66
pub enum Expr<'src> {
7+
Mod(&'src str),
78
Use(ExprUse<'src>),
89
Other(&'src str),
910
}

rust/rustell/tests/integration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ fn test_parser_mixed_all_cases() {
325325
assert_eq!(decode(&encode(&rhs)), rhs)
326326
}
327327

328+
#[test]
329+
fn test_rountrip_lib() {
330+
let src =
331+
std::fs::read_to_string("./src/lib.rs").unwrap();
332+
let ast = decode(&src);
333+
assert_eq!(decode(&encode(&ast)), ast);
334+
}
335+
328336
fn sloppy(src: &str) -> String {
329337
src.replace(";", "")
330338
}

0 commit comments

Comments
 (0)