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

[reference-bindings] Change the parser to refer to 'VariableBindings' instead of 'letOrVar' in preparation for adding inout and borrow bindings. #1354

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ public let DECL_NODES: [Node] = [
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
nameForDiagnostics: "modifiers",
isOptional: true),
Child(name: "LetOrVarKeyword",
Child(name: "BindingKeyword",
kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var")])),
Child(name: "Bindings",
kind: .collection(kind: "PatternBindingList", collectionElementName: "Binding"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public let PATTERN_NODES: [Node] = [
nameForDiagnostics: "value binding pattern",
kind: "Pattern",
children: [
Child(name: "LetOrVarKeyword",
Child(name: "BindingKeyword",
kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var")])),
Child(name: "ValuePattern",
kind: .node(kind: "Pattern"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public let STMT_NODES: [Node] = [
nameForDiagnostics: "optional binding",
kind: "Syntax",
children: [
Child(name: "LetOrVarKeyword",
Child(name: "BindingKeyword",
kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var")])),
Child(name: "Pattern",
kind: .node(kind: "Pattern")),
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ extension Parser {
case (.subscriptKeyword, let handle)?:
return RawDeclSyntax(self.parseSubscriptDeclaration(attrs, handle))
case (.letKeyword, let handle)?, (.varKeyword, let handle)?:
return RawDeclSyntax(self.parseLetOrVarDeclaration(attrs, handle, inMemberDeclList: inMemberDeclList))
return RawDeclSyntax(self.parseBindingDeclaration(attrs, handle, inMemberDeclList: inMemberDeclList))
case (.initKeyword, let handle)?:
return RawDeclSyntax(self.parseInitializerDeclaration(attrs, handle))
case (.deinitKeyword, let handle)?:
Expand All @@ -261,7 +261,7 @@ extension Parser {
let isProbablyTupleDecl = self.at(.leftParen) && self.peek().rawTokenKind.is(.identifier, .wildcard)

if isProbablyVarDecl || isProbablyTupleDecl {
return RawDeclSyntax(self.parseLetOrVarDeclaration(attrs, .missing(.keyword(.var))))
return RawDeclSyntax(self.parseBindingDeclaration(attrs, .missing(.keyword(.var))))
}

if self.currentToken.isEditorPlaceholder {
Expand Down Expand Up @@ -1471,7 +1471,7 @@ extension Parser {
/// }
/// ```
@_spi(RawSyntax)
public mutating func parseLetOrVarDeclaration(
public mutating func parseBindingDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle,
inMemberDeclList: Bool = false
Expand Down Expand Up @@ -1571,7 +1571,7 @@ extension Parser {
attributes: attrs.attributes,
modifiers: attrs.modifiers,
unexpectedBeforeIntroducer,
letOrVarKeyword: introducer,
bindingKeyword: introducer,
bindings: RawPatternBindingListSyntax(elements: elements, arena: self.arena),
arena: self.arena
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extension Parser {
let value = self.parsePattern()
return RawPatternSyntax(
RawValueBindingPatternSyntax(
letOrVarKeyword: letOrVar,
bindingKeyword: letOrVar,
valuePattern: value,
arena: self.arena
)
Expand Down Expand Up @@ -244,7 +244,7 @@ extension Parser {
let value = self.parseMatchingPattern(context: .letOrVar)
return RawPatternSyntax(
RawValueBindingPatternSyntax(
letOrVarKeyword: letOrVar,
bindingKeyword: letOrVar,
valuePattern: value,
arena: self.arena
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ extension Parser {
case let .optional(letOrVar, pattern):
return .optionalBinding(
RawOptionalBindingConditionSyntax(
letOrVarKeyword: letOrVar,
bindingKeyword: letOrVar,
pattern: pattern,
typeAnnotation: annotation,
initializer: initializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
return $0.initializer?.value.as(TryExprSyntax.self)?.tryKeyword
})
exchangeTokens(
unexpected: node.unexpectedBetweenModifiersAndLetOrVarKeyword,
unexpected: node.unexpectedBetweenModifiersAndBindingKeyword,
unexpectedTokenCondition: { $0.tokenKind == .keyword(.try) },
correctTokens: missingTries,
message: { _ in .tryOnInitialValueExpression },
Expand Down
54 changes: 27 additions & 27 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13718,9 +13718,9 @@ public struct RawOptionalBindingConditionSyntax: RawSyntaxNodeProtocol {
}

public init(
_ unexpectedBeforeLetOrVarKeyword: RawUnexpectedNodesSyntax? = nil,
letOrVarKeyword: RawTokenSyntax,
_ unexpectedBetweenLetOrVarKeywordAndPattern: RawUnexpectedNodesSyntax? = nil,
_ unexpectedBeforeBindingKeyword: RawUnexpectedNodesSyntax? = nil,
bindingKeyword: RawTokenSyntax,
_ unexpectedBetweenBindingKeywordAndPattern: RawUnexpectedNodesSyntax? = nil,
pattern: RawPatternSyntax,
_ unexpectedBetweenPatternAndTypeAnnotation: RawUnexpectedNodesSyntax? = nil,
typeAnnotation: RawTypeAnnotationSyntax?,
Expand All @@ -13732,9 +13732,9 @@ public struct RawOptionalBindingConditionSyntax: RawSyntaxNodeProtocol {
let raw = RawSyntax.makeLayout(
kind: .optionalBindingCondition, uninitializedCount: 9, arena: arena) { layout in
layout.initialize(repeating: nil)
layout[0] = unexpectedBeforeLetOrVarKeyword?.raw
layout[1] = letOrVarKeyword.raw
layout[2] = unexpectedBetweenLetOrVarKeywordAndPattern?.raw
layout[0] = unexpectedBeforeBindingKeyword?.raw
layout[1] = bindingKeyword.raw
layout[2] = unexpectedBetweenBindingKeywordAndPattern?.raw
layout[3] = pattern.raw
layout[4] = unexpectedBetweenPatternAndTypeAnnotation?.raw
layout[5] = typeAnnotation?.raw
Expand All @@ -13745,15 +13745,15 @@ public struct RawOptionalBindingConditionSyntax: RawSyntaxNodeProtocol {
self.init(raw: raw)
}

public var unexpectedBeforeLetOrVarKeyword: RawUnexpectedNodesSyntax? {
public var unexpectedBeforeBindingKeyword: RawUnexpectedNodesSyntax? {
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var letOrVarKeyword: RawTokenSyntax {
public var bindingKeyword: RawTokenSyntax {
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
}

public var unexpectedBetweenLetOrVarKeywordAndPattern: RawUnexpectedNodesSyntax? {
public var unexpectedBetweenBindingKeywordAndPattern: RawUnexpectedNodesSyntax? {
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
}

Expand Down Expand Up @@ -19827,34 +19827,34 @@ public struct RawValueBindingPatternSyntax: RawPatternSyntaxNodeProtocol {
}

public init(
_ unexpectedBeforeLetOrVarKeyword: RawUnexpectedNodesSyntax? = nil,
letOrVarKeyword: RawTokenSyntax,
_ unexpectedBetweenLetOrVarKeywordAndValuePattern: RawUnexpectedNodesSyntax? = nil,
_ unexpectedBeforeBindingKeyword: RawUnexpectedNodesSyntax? = nil,
bindingKeyword: RawTokenSyntax,
_ unexpectedBetweenBindingKeywordAndValuePattern: RawUnexpectedNodesSyntax? = nil,
valuePattern: RawPatternSyntax,
_ unexpectedAfterValuePattern: RawUnexpectedNodesSyntax? = nil,
arena: __shared SyntaxArena
) {
let raw = RawSyntax.makeLayout(
kind: .valueBindingPattern, uninitializedCount: 5, arena: arena) { layout in
layout.initialize(repeating: nil)
layout[0] = unexpectedBeforeLetOrVarKeyword?.raw
layout[1] = letOrVarKeyword.raw
layout[2] = unexpectedBetweenLetOrVarKeywordAndValuePattern?.raw
layout[0] = unexpectedBeforeBindingKeyword?.raw
layout[1] = bindingKeyword.raw
layout[2] = unexpectedBetweenBindingKeywordAndValuePattern?.raw
layout[3] = valuePattern.raw
layout[4] = unexpectedAfterValuePattern?.raw
}
self.init(raw: raw)
}

public var unexpectedBeforeLetOrVarKeyword: RawUnexpectedNodesSyntax? {
public var unexpectedBeforeBindingKeyword: RawUnexpectedNodesSyntax? {
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var letOrVarKeyword: RawTokenSyntax {
public var bindingKeyword: RawTokenSyntax {
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
}

public var unexpectedBetweenLetOrVarKeywordAndValuePattern: RawUnexpectedNodesSyntax? {
public var unexpectedBetweenBindingKeywordAndValuePattern: RawUnexpectedNodesSyntax? {
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
}

Expand Down Expand Up @@ -19897,9 +19897,9 @@ public struct RawVariableDeclSyntax: RawDeclSyntaxNodeProtocol {
attributes: RawAttributeListSyntax?,
_ unexpectedBetweenAttributesAndModifiers: RawUnexpectedNodesSyntax? = nil,
modifiers: RawModifierListSyntax?,
_ unexpectedBetweenModifiersAndLetOrVarKeyword: RawUnexpectedNodesSyntax? = nil,
letOrVarKeyword: RawTokenSyntax,
_ unexpectedBetweenLetOrVarKeywordAndBindings: RawUnexpectedNodesSyntax? = nil,
_ unexpectedBetweenModifiersAndBindingKeyword: RawUnexpectedNodesSyntax? = nil,
bindingKeyword: RawTokenSyntax,
_ unexpectedBetweenBindingKeywordAndBindings: RawUnexpectedNodesSyntax? = nil,
bindings: RawPatternBindingListSyntax,
_ unexpectedAfterBindings: RawUnexpectedNodesSyntax? = nil,
arena: __shared SyntaxArena
Expand All @@ -19911,9 +19911,9 @@ public struct RawVariableDeclSyntax: RawDeclSyntaxNodeProtocol {
layout[1] = attributes?.raw
layout[2] = unexpectedBetweenAttributesAndModifiers?.raw
layout[3] = modifiers?.raw
layout[4] = unexpectedBetweenModifiersAndLetOrVarKeyword?.raw
layout[5] = letOrVarKeyword.raw
layout[6] = unexpectedBetweenLetOrVarKeywordAndBindings?.raw
layout[4] = unexpectedBetweenModifiersAndBindingKeyword?.raw
layout[5] = bindingKeyword.raw
layout[6] = unexpectedBetweenBindingKeywordAndBindings?.raw
layout[7] = bindings.raw
layout[8] = unexpectedAfterBindings?.raw
}
Expand All @@ -19936,15 +19936,15 @@ public struct RawVariableDeclSyntax: RawDeclSyntaxNodeProtocol {
layoutView.children[3].map(RawModifierListSyntax.init(raw:))
}

public var unexpectedBetweenModifiersAndLetOrVarKeyword: RawUnexpectedNodesSyntax? {
public var unexpectedBetweenModifiersAndBindingKeyword: RawUnexpectedNodesSyntax? {
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var letOrVarKeyword: RawTokenSyntax {
public var bindingKeyword: RawTokenSyntax {
layoutView.children[5].map(RawTokenSyntax.init(raw:))!
}

public var unexpectedBetweenLetOrVarKeywordAndBindings: RawUnexpectedNodesSyntax? {
public var unexpectedBetweenBindingKeywordAndBindings: RawUnexpectedNodesSyntax? {
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
}

Expand Down
36 changes: 18 additions & 18 deletions Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7303,9 +7303,9 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
attributes: AttributeListSyntax? = nil,
_ unexpectedBetweenAttributesAndModifiers: UnexpectedNodesSyntax? = nil,
modifiers: ModifierListSyntax? = nil,
_ unexpectedBetweenModifiersAndLetOrVarKeyword: UnexpectedNodesSyntax? = nil,
letOrVarKeyword: TokenSyntax,
_ unexpectedBetweenLetOrVarKeywordAndBindings: UnexpectedNodesSyntax? = nil,
_ unexpectedBetweenModifiersAndBindingKeyword: UnexpectedNodesSyntax? = nil,
bindingKeyword: TokenSyntax,
_ unexpectedBetweenBindingKeywordAndBindings: UnexpectedNodesSyntax? = nil,
bindings: PatternBindingListSyntax,
_ unexpectedAfterBindings: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
Expand All @@ -7318,9 +7318,9 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
attributes,
unexpectedBetweenAttributesAndModifiers,
modifiers,
unexpectedBetweenModifiersAndLetOrVarKeyword,
letOrVarKeyword,
unexpectedBetweenLetOrVarKeywordAndBindings,
unexpectedBetweenModifiersAndBindingKeyword,
bindingKeyword,
unexpectedBetweenBindingKeywordAndBindings,
bindings,
unexpectedAfterBindings
))) {(arena, _) in
Expand All @@ -7329,9 +7329,9 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
attributes?.raw,
unexpectedBetweenAttributesAndModifiers?.raw,
modifiers?.raw,
unexpectedBetweenModifiersAndLetOrVarKeyword?.raw,
letOrVarKeyword.raw,
unexpectedBetweenLetOrVarKeywordAndBindings?.raw,
unexpectedBetweenModifiersAndBindingKeyword?.raw,
bindingKeyword.raw,
unexpectedBetweenBindingKeywordAndBindings?.raw,
bindings.raw,
unexpectedAfterBindings?.raw
]
Expand Down Expand Up @@ -7421,7 +7421,7 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
return VariableDeclSyntax(newData)
}

public var unexpectedBetweenModifiersAndLetOrVarKeyword: UnexpectedNodesSyntax? {
public var unexpectedBetweenModifiersAndBindingKeyword: UnexpectedNodesSyntax? {
get {
return data.child(at: 4, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
}
Expand All @@ -7430,7 +7430,7 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
}
}

public var letOrVarKeyword: TokenSyntax {
public var bindingKeyword: TokenSyntax {
get {
return TokenSyntax(data.child(at: 5, parent: Syntax(self))!)
}
Expand All @@ -7439,7 +7439,7 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
}
}

public var unexpectedBetweenLetOrVarKeywordAndBindings: UnexpectedNodesSyntax? {
public var unexpectedBetweenBindingKeywordAndBindings: UnexpectedNodesSyntax? {
get {
return data.child(at: 6, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
}
Expand Down Expand Up @@ -7491,9 +7491,9 @@ public struct VariableDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
\Self.attributes,
\Self.unexpectedBetweenAttributesAndModifiers,
\Self.modifiers,
\Self.unexpectedBetweenModifiersAndLetOrVarKeyword,
\Self.letOrVarKeyword,
\Self.unexpectedBetweenLetOrVarKeywordAndBindings,
\Self.unexpectedBetweenModifiersAndBindingKeyword,
\Self.bindingKeyword,
\Self.unexpectedBetweenBindingKeywordAndBindings,
\Self.bindings,
\Self.unexpectedAfterBindings
])
Expand Down Expand Up @@ -7532,9 +7532,9 @@ extension VariableDeclSyntax: CustomReflectable {
"attributes": attributes.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"unexpectedBetweenAttributesAndModifiers": unexpectedBetweenAttributesAndModifiers.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"modifiers": modifiers.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"unexpectedBetweenModifiersAndLetOrVarKeyword": unexpectedBetweenModifiersAndLetOrVarKeyword.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"letOrVarKeyword": Syntax(letOrVarKeyword).asProtocol(SyntaxProtocol.self),
"unexpectedBetweenLetOrVarKeywordAndBindings": unexpectedBetweenLetOrVarKeywordAndBindings.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"unexpectedBetweenModifiersAndBindingKeyword": unexpectedBetweenModifiersAndBindingKeyword.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"bindingKeyword": Syntax(bindingKeyword).asProtocol(SyntaxProtocol.self),
"unexpectedBetweenBindingKeywordAndBindings": unexpectedBetweenBindingKeywordAndBindings.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any ,
"bindings": Syntax(bindings).asProtocol(SyntaxProtocol.self),
"unexpectedAfterBindings": unexpectedAfterBindings.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any
])
Expand Down
Loading