Skip to content

Commit

Permalink
fix raw sym/key parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 6, 2023
1 parent 85fffe0 commit e7062ba
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ pub fn parse_relative_path<F: LurkField>() -> impl Fn(Span<'_>) -> ParseResult<'
pub fn parse_raw_path<F: LurkField>() -> impl Fn(Span<'_>) -> ParseResult<'_, F, Syntax<F>> {
move |from: Span<'_>| {
let (i, _) = tag("~(")(from)?;
let (i, path) = many0(preceded(parse_space, parse_path_component_raw("|()")))(i)?;
let (i, mut path) = many0(preceded(parse_space, parse_path_component_raw("|()")))(i)?;
let (upto, _) = many_till(parse_space, tag(")"))(i)?;
path.reverse();
Ok((upto, Syntax::Path(Pos::from_upto(from, upto), path, false)))
}
}
Expand All @@ -117,16 +118,17 @@ pub fn parse_raw_keyword_path<F: LurkField>() -> impl Fn(Span<'_>) -> ParseResul
{
move |from: Span<'_>| {
let (i, _) = tag("~:(")(from)?;
let (i, path) = many0(preceded(parse_space, parse_path_component_raw("|()")))(i)?;
let (i, mut path) = many0(preceded(parse_space, parse_path_component_raw("|()")))(i)?;
let (upto, _) = many_till(parse_space, tag(")"))(i)?;
path.reverse();
Ok((upto, Syntax::Path(Pos::from_upto(from, upto), path, true)))
}
}

/// relative: foo.bar
/// absolute: .foo.bar.baz, :foo.bar (escaped limbs: .|foo|.|bar|.|baz|)
/// raw: ~(foo bar baz) = .|foo|.|bar|.|baz|
/// raw keyword: ~:(foo bar)
/// raw: ~(foo bar baz) = .baz.bar.foo
/// raw keyword: ~:(foo bar) = :bar.foo
pub fn parse_path<F: LurkField>() -> impl Fn(Span<'_>) -> ParseResult<'_, F, Syntax<F>> {
move |from: Span<'_>| {
alt((
Expand Down Expand Up @@ -447,12 +449,12 @@ pub mod tests {
assert!(test(
parse_path(),
"~(asdf.fdsa arst)",
Some(sym_path!(["asdf.fdsa", "arst"]))
Some(sym_path!(["arst", "asdf.fdsa"]))
));
assert!(test(
parse_path(),
"~(asdf.fdsa arst |wfp qwf|)",
Some(sym_path!(["asdf.fdsa", "arst", "wfp qwf"]))
Some(sym_path!(["wfp qwf", "arst", "asdf.fdsa"]))
));
}

Expand Down Expand Up @@ -495,6 +497,11 @@ pub mod tests {
":foo\\.bar",
Some(key_path!(["foo.bar"]))
));
assert!(test(
parse_path(),
"~:(x y z)",
Some(key_path!(["z", "y", "x"]))
));
}

#[test]
Expand Down

0 comments on commit e7062ba

Please sign in to comment.