Skip to content

Add a recursive hasError flag to RawSyntax #596

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

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 16, 2022

This allows us to check whether a subtree contains a syntax error in O(1).

rdar://98575249

@ahoppen ahoppen requested a review from rintaro August 16, 2022 18:48
@@ -172,6 +174,13 @@ extension RawSyntax {
kind.isUnknown
}

var hasError: Bool {
switch rawData.payload {
case .materializedToken(_): return self.presence == .missing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to detect the presence of the node purely based on the materializedToken but I’m worried that will break if we change whether tokens without source text but with trivia are considered missing.

@ahoppen
Copy link
Member Author

ahoppen commented Aug 16, 2022

@swift-ci Please test

@rintaro
Copy link
Member

rintaro commented Aug 16, 2022

I realized that we might need/want this flag in ParsedToken(#597) too. Because for example the parser might want to lex unterminated regex literal as a .regexLiteral. For later diagnostics, without the flag in ParsedToken, we need to look into every .regexLiteral token if it has any error or not. Same for stringLiteral.

@ahoppen
Copy link
Member Author

ahoppen commented Aug 17, 2022

@swift-ci Please test

@@ -172,6 +187,19 @@ extension RawSyntax {
kind.isUnknown
}

var recursiveFlags: RecursiveRawSyntaxFlags {
switch rawData.payload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I merged ParsedToken PR, this switch needs to handle it. Sorry 🙇

This allows us to check whether a subtree contains a syntax error in O(1).

rdar://98575249
@ahoppen
Copy link
Member Author

ahoppen commented Aug 17, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit cdf111e into swiftlang:main Aug 18, 2022
@ahoppen ahoppen deleted the pr/has-error branch August 18, 2022 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants