Skip to content

Commit 5aa1c6b

Browse files
committed
typed ast tokens fix
1 parent 1d24c9f commit 5aa1c6b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

rust/rustell/src/decode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ fn expr_mod<'a>() -> impl Decode<'a, Expr<'a>> {
2727
let tok =
2828
token(text::ascii::ident()).and_is(keyword().not());
2929
just("mod")
30+
.then_ignore(whitespace().at_least(1))
3031
.ignore_then(tok)
3132
.then_ignore(lexeme(";").or_not())
3233
.map(Expr::Mod)
3334
}
3435

3536
fn expr_use<'a>() -> impl Decode<'a, Expr<'a>> {
3637
just("use")
38+
.then_ignore(whitespace().at_least(1))
3739
.ignore_then(expr_use_rec())
3840
.then_ignore(lexeme(";").or_not())
3941
.map(Expr::Use)

rust/rustell/tests/integration.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,76 @@ fn mixed_use_and_raw_cases() {
397397
assert_eq!(decode(&encode(&rhs)), rhs)
398398
}
399399

400+
#[test]
401+
fn small_mixed_lib() {
402+
let lhs = r#"
403+
pub mod decode;
404+
pub mod encode;
405+
pub use chumsky::prelude::Parser;
406+
407+
#[derive(Eq, PartialEq, Debug, Clone)]
408+
pub enum Expr<'a> {
409+
Mod(&'a str),
410+
Use(ExprUse<'a>),
411+
Raw(&'a str),
412+
}
413+
414+
#[derive(Eq, PartialEq, Debug, Clone)]
415+
pub enum ExprUse<'a> {
416+
Item {
417+
module: &'a str,
418+
rename: Option<&'a str>,
419+
nested: Option<Box<ExprUse<'a>>>,
420+
},
421+
Many(Vec<ExprUse<'a>>),
422+
Glob,
423+
}"#;
424+
let rhs = vec![
425+
Expr::Raw("\n pub "),
426+
Expr::Mod("decode"),
427+
Expr::Raw("\n pub "),
428+
Expr::Mod("encode"),
429+
Expr::Raw("\n pub "),
430+
Expr::Use(ExprUse::Item {
431+
module: "chumsky",
432+
rename: None,
433+
nested: Some(Box::new(ExprUse::Item {
434+
module: "prelude",
435+
rename: None,
436+
nested: Some(Box::new(ExprUse::Item {
437+
module: "Parser",
438+
rename: None,
439+
nested: None,
440+
})),
441+
})),
442+
}),
443+
Expr::Raw(
444+
r#"
445+
446+
#[derive(Eq, PartialEq, Debug, Clone)]
447+
pub enum Expr<'a> {
448+
Mod(&'a str),
449+
Use(ExprUse<'a>),
450+
Raw(&'a str),
451+
}
452+
453+
#[derive(Eq, PartialEq, Debug, Clone)]
454+
pub enum ExprUse<'a> {
455+
Item {
456+
module: &'a str,
457+
rename: Option<&'a str>,
458+
nested: Option<Box<ExprUse<'a>>>,
459+
},
460+
Many(Vec<ExprUse<'a>>),
461+
Glob,
462+
}"#,
463+
),
464+
];
465+
assert_eq!(decode(lhs), rhs);
466+
assert_eq!(decode(&sloppy(lhs)), rhs);
467+
assert_eq!(decode(&encode(&rhs)), rhs)
468+
}
469+
400470
#[test]
401471
fn roundtrip_source_files() {
402472
get_rust_files("./").into_iter().for_each(|path| {

0 commit comments

Comments
 (0)