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

Implement better error recovery for parsing of separated syntax lists #20

Open
alexrp opened this issue Feb 18, 2023 · 4 comments
Open
Labels
area: analysis Issues related to language analyses. area: tests Issues related to the test suite. state: approved Enhancements and tasks that have been approved.
Milestone

Comments

@alexrp
Copy link
Member

alexrp commented Feb 18, 2023

private (ImmutableArray<T>.Builder Elements, ImmutableArray<SyntaxToken>.Builder Separators) ParseSeparatedList<T>(
Func<LanguageParser, T> parser,
SyntaxTokenKind separator,
SyntaxTokenKind closer,
bool allowEmpty,
bool allowTrailing)
where T : SyntaxNode
{
// TODO: The way we parse a parameter list (and other similar syntax nodes) causes the parser to misinterpret
// the entire function body for some invalid inputs. We need to do better here.
var result = SeparatedBuilder<T>();
var (elems, seps) = result;
bool NextIsRelevant()
{
return Peek1() is { IsEndOfInput: false } next && next.Kind != closer;
}
if (!allowTrailing)
{
if (allowEmpty && !NextIsRelevant())
return result;
elems.Add(parser(this));
while (Optional(separator) is { } sep)
{
seps.Add(sep);
elems.Add(parser(this));
}
return result;
}
if (!allowEmpty)
{
elems.Add(parser(this));
if (Optional(separator) is not { } sep)
return result;
seps.Add(sep);
}
while (NextIsRelevant())
{
elems.Add(parser(this));
if (Optional(separator) is not { } sep2)
break;
seps.Add(sep2);
}
return result;
}

@alexrp alexrp added state: deliberation Issues that require design work and/or discussion. type: feature area: analysis Issues related to language analyses. labels Feb 18, 2023
@alexrp alexrp added this to the v1.0 milestone Feb 18, 2023
@alexrp alexrp self-assigned this Feb 18, 2023
@alexrp alexrp changed the title Implement better error recovery for parsing separated syntax lists Implement better error recovery for parsing of separated syntax lists Feb 18, 2023
@alexrp
Copy link
Member Author

alexrp commented Feb 18, 2023

To solve this, we will likely need a more general mechanism for dealing with skipped tokens. One approach might be to decay skipped tokens to text and attach them as trivia to another token (whether real or IsMissing).

@alexrp alexrp added state: approved Enhancements and tasks that have been approved. and removed state: deliberation Issues that require design work and/or discussion. labels Feb 23, 2023
@alexrp
Copy link
Member Author

alexrp commented Mar 4, 2023

One approach might be to decay skipped tokens to text and attach them as trivia to another token (whether real or IsMissing).

This is almost certainly the way we'll go.

Note to future self: There's some code that assumes that SyntaxToken.IsMissing implies SyntaxToken.FullSpan.IsEmpty, which would no longer hold if such a token has skipped trivia attached. This will need to be fixed.

@alexrp
Copy link
Member Author

alexrp commented Mar 18, 2023

Support for skipped token trivia has been added. This situation can be improved now.

@alexrp alexrp added the area: tests Issues related to the test suite. label Mar 21, 2023
@alexrp alexrp removed their assignment Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: analysis Issues related to language analyses. area: tests Issues related to the test suite. state: approved Enhancements and tasks that have been approved.
Development

No branches or pull requests

1 participant