Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More helpful error messages #56

Open
aaronjanse opened this issue Nov 11, 2021 · 3 comments
Open

More helpful error messages #56

aaronjanse opened this issue Nov 11, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@aaronjanse
Copy link
Member

aaronjanse commented Nov 11, 2021

It would be great if rnix-parser has errors more descriptive than "unexpected X," perhaps prompting the user how to fix the code if we can guess what's missing (e.g. a semicolon for the last value in an attr set)?

Existing error messages at the time of writing:

#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ParseError {
/// Unexpected is used when the cause cannot be specified further
Unexpected(TextRange),
/// UnexpectedExtra is used when there are additional tokens to the root in the tree
UnexpectedExtra(TextRange),
/// UnexpectedWanted is used when specific tokens are expected, but different one is found
UnexpectedWanted(SyntaxKind, TextRange, Box<[SyntaxKind]>),
/// UnexpectedDoubleBind is used when a pattern is bound twice
UnexpectedDoubleBind(TextRange),
/// UnexpectedEOF is used when the end of file is reached, while tokens are still expected
UnexpectedEOF,
/// UnexpectedEOFWanted is used when specific tokens are expected, but the end of file is reached
UnexpectedEOFWanted(Box<[SyntaxKind]>),
}

@aaronjanse aaronjanse added the enhancement New feature or request label Nov 11, 2021
@Ma27 Ma27 added this to the 1.0.0 milestone Nov 11, 2021
@Ma27
Copy link
Member

Ma27 commented Nov 11, 2021

Seems reasonable. Will be out of scope for 0.10. though, hope that's OK :)

@Ma27 Ma27 added the help wanted Extra attention is needed label Nov 11, 2021
@Ma27
Copy link
Member

Ma27 commented Nov 11, 2021

In case someone wants to take over, feel free.... Otherwise I'll look into it as soon as we're working on 1.0.

@elikoga
Copy link

elikoga commented Jan 25, 2023

Just to be clear, this is about improving the Display impl for ParseError? As in expanding on the strings

See

"error node at {}..{}",
usize::from(range.start()),
usize::from(range.end())
)
}
ParseError::UnexpectedExtra(range) => {
write!(
f,
"unexpected token at {}..{}",
usize::from(range.start()),
usize::from(range.end())
)
}
ParseError::UnexpectedWanted(got, range, kinds) => write!(
f,
"unexpected {:?} at {}..{}, wanted any of {:?}",
got,
usize::from(range.start()),
usize::from(range.end()),
kinds
),
ParseError::UnexpectedDoubleBind(range) => {
write!(
f,
"unexpected double bind at {}..{}",
usize::from(range.start()),
usize::from(range.end())
)
}
ParseError::UnexpectedEOF => write!(f, "unexpected end of file"),
ParseError::UnexpectedEOFWanted(kinds) => {
write!(f, "unexpected end of file, wanted any of {:?}", kinds)
}
ParseError::DuplicatedArgs(range, ident) => {
write!(
f,
"argument `{}` is duplicated in {}..{}",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants