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

[NFC] Simplify some value bindings #1406

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Sources/SwiftParser/Patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,28 +242,29 @@ extension Parser {
mutating func parseMatchingPattern(context: PatternContext) -> RawPatternSyntax {
// Parse productions that can only be patterns.
switch self.at(anyIn: MatchingPatternStart.self) {
case (.varKeyword, let handle)?,
(.letKeyword, let handle)?,
(.inoutKeyword, let handle)?:
let bindingKeyword = self.eat(handle)
let value = self.parseMatchingPattern(context: .bindingIntroducer)
return RawPatternSyntax(
RawValueBindingPatternSyntax(
bindingKeyword: bindingKeyword,
valuePattern: value,
arena: self.arena
case let .some((patternStart, handle)):
switch patternStart {
case .varKeyword, .letKeyword, .inoutKeyword:
let bindingKeyword = self.eat(handle)
let value = self.parseMatchingPattern(context: .bindingIntroducer)
return RawPatternSyntax(
RawValueBindingPatternSyntax(
bindingKeyword: bindingKeyword,
valuePattern: value,
arena: self.arena
)
)
)
case (.isKeyword, let handle)?:
let isKeyword = self.eat(handle)
let type = self.parseType()
return RawPatternSyntax(
RawIsTypePatternSyntax(
isKeyword: isKeyword,
type: type,
arena: self.arena
case .isKeyword:
let isKeyword = self.eat(handle)
let type = self.parseType()
return RawPatternSyntax(
RawIsTypePatternSyntax(
isKeyword: isKeyword,
type: type,
arena: self.arena
)
)
)
}
case nil:
// matching-pattern ::= expr
// Fall back to expression parsing for ambiguous forms. Name lookup will
Expand Down