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

[SwiftParser] Support function body and type member skipping #2316

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Oct 29, 2023

  • Introduce ParsingOptions option-set type with bodySkipping member, and add options: ParsingOptions to all Parser.parse(...) functions
  • Skipped body is represented as a newly introduced SkippedDeclSyntax
    • SkippedDeclSyntax contains only one .unknown token that covers the whole skipped characters including trivia.
  • Function body can be skipped as long as:
    • it does not contain nested type decls
  • Type member block can be skipped as long as:
    • it does not contain nested class decls
    • it does not contain operator functions
    • it does not contain #if directives

@rintaro rintaro marked this pull request as draft October 29, 2023 05:15
@@ -2791,6 +2791,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
return "closingQuote"
case \SimpleStringLiteralExprSyntax.unexpectedAfterClosingQuote:
return "unexpectedAfterClosingQuote"
case \SkippedDeclSyntax.unexpectedBeforeText:
return "unexpectedBeforeText"
Copy link
Member Author

Choose a reason for hiding this comment

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

Can we remove these unexpected items?

Comment on lines 1239 to 1240
if let peekedScalar = start.peekScalar(), peekedScalar.isValidIdentifierStartCodePoint {
break
}
if let peekedScalar = start.peekScalar(), peekedScalar.isOperatorStartCodePoint {
if let peekedScalar = start.peekScalar(),
peekedScalar.isValidIdentifierStartCodePoint || peekedScalar.isOperatorStartCodePoint {
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated?

mutating func skippedBraceBody(unless: Lookahead.SkipBodyResult) -> RawSkippedDeclSyntax? {
return self.withLookahead { lookahead in
let result = lookahead.advanceUntilMatchingRightBrace()
guard result.isDisjoint(with: unless) else {
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of checking the result on the skipped area, the skipping function should bail out and return nil as soon as it finds any unless condition.

Comment on lines +40 to +43
// Nested class. Because?
if tokenKind == .keyword && tokenText == "class" {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's because of AnyObject lookup :shakesfist:

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.

None yet

2 participants