-
I tried to set up ariadne based on your JSON example, and it works like a charm. I just have a small question regarding the precision of the diagnostic. I have the following parser: pub(crate) fn single_part<'a>() -> impl Parser<'a, &'a str, Part, extra::Err<Rich<'a, char>>> + Clone
{
just(SINGLE_PART_BEGIN)
.ignore_then(
choice((
part_type(),
name(),
disposition(),
#[cfg(feature = "pgp")]
encrypt(),
#[cfg(feature = "pgp")]
sign(),
))
.repeated()
.collect::<HashMap<_, _>>()
.then_ignore(just(GREATER_THAN))
.then_ignore(just(NEW_LINE).or_not()),
)
.then(text_plain_part())
.then_ignore(just(SINGLE_PART_END).then(just(NEW_LINE).or_not()).or_not())
.map(|(props, content)| Part::SinglePart(props, content))
} When I try to parse an invalid prop like:
Is there by any chance a way to ask the parser to show full names |
Beta Was this translation helpful? Give feedback.
Answered by
zesterer
Sep 16, 2023
Replies: 1 comment 3 replies
-
How are |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a product of the fact that
just
works on the level of tokens (in your case,char
s), even when given a sequence (like"foo"
). Chumsky provides a way to 'realias' a parser in error messages: the.labelled(...)
combinator (on 1.0, you'll need to enable thelabel
feature). Now you can do this:And you'll get something like this in the error message:
labelled
works on all parsers, even much more complex ones. This allows you to realias an entire pattern (such as 'expressions') and have something likefound '#', expected expression
appear in your error message. For example, thenano_rust
example uses this to produce easier to u…