Skip to content
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 @@ -89,7 +89,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
var fileSpecs: [GeneratedFileSpec] = [
// SwiftParser
GeneratedFileSpec(swiftParserGeneratedDir + ["IsLexerClassified.swift"], isLexerClassifiedFile),
GeneratedFileSpec(swiftParserGeneratedDir + ["LayoutNodes+Parsable.swift"], parserEntryFile),
GeneratedFileSpec(swiftParserGeneratedDir + ["LayoutNodes+Parsable.swift"], layoutNodesParsableFile),
GeneratedFileSpec(swiftParserGeneratedDir + ["Parser+TokenSpecSet.swift"], parserTokenSpecSetFile),
GeneratedFileSpec(swiftParserGeneratedDir + ["TokenSpecStaticMembers.swift"], tokenSpecStaticMembersFile),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftSyntaxBuilder
import SyntaxSupport
import Utils

let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
let layoutNodesParsableFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")

DeclSyntax(
Expand Down Expand Up @@ -74,5 +74,13 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
}
"""
)

DeclSyntax(
"""
mutating func parseExpression() -> RawExprSyntax {
return self.parseExpression(flavor: .basic, pattern: .none)
}
"""
)
}
}
15 changes: 7 additions & 8 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ extension Parser {
// See if there's a raw value expression.
let rawValue: RawInitializerClauseSyntax?
if let eq = self.consume(if: .equal) {
let value = self.parseExpression()
let value = self.parseExpression(flavor: .basic, pattern: .none)
rawValue = RawInitializerClauseSyntax(
equal: eq,
value: value,
Expand Down Expand Up @@ -1219,7 +1219,7 @@ extension Parser {
// Parse an initializer if present.
let initializer: RawInitializerClauseSyntax?
if let equal = self.consume(if: .equal) {
var value = self.parseExpression()
var value = self.parseExpression(flavor: .basic, pattern: .none)
if hasTryBeforeIntroducer && !value.is(RawTryExprSyntax.self) {
value = RawExprSyntax(
RawTryExprSyntax(
Expand Down Expand Up @@ -1250,8 +1250,7 @@ extension Parser {
arena: self.arena
)
),
.basic,
forDirective: false,
flavor: .basic,
pattern: .none
)
initializer = RawInitializerClauseSyntax(
Expand All @@ -1268,7 +1267,7 @@ extension Parser {
)
} else if self.atStartOfExpression(), !self.at(.leftBrace), !self.atStartOfLine {
let missingEqual = RawTokenSyntax(missing: .equal, arena: self.arena)
let expr = self.parseExpression()
let expr = self.parseExpression(flavor: .basic, pattern: .none)
initializer = RawInitializerClauseSyntax(
equal: missingEqual,
value: expr,
Expand Down Expand Up @@ -1849,7 +1848,7 @@ extension Parser {
// Initializer, if any.
let definition: RawInitializerClauseSyntax?
if let equal = self.consume(if: .equal) {
let expr = self.parseExpression()
let expr = self.parseExpression(flavor: .basic, pattern: .none)
definition = RawInitializerClauseSyntax(
equal: equal,
value: expr,
Expand Down Expand Up @@ -1933,10 +1932,10 @@ extension Parser {
let trailingClosure: RawClosureExprSyntax?
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax
if self.at(.leftBrace),
self.withLookahead({ $0.atValidTrailingClosure(.trailingClosure) })
self.withLookahead({ $0.atValidTrailingClosure(flavor: .basic) })
{
(trailingClosure, additionalTrailingClosures) =
self.parseTrailingClosures(.trailingClosure)
self.parseTrailingClosures(flavor: .basic)
} else {
trailingClosure = nil
additionalTrailingClosures = self.emptyCollection(RawMultipleTrailingClosureElementListSyntax.self)
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftParser/Directives.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Parser {

// Parse #if
let (unexpectedBeforePoundIf, poundIf) = self.expect(.poundIf)
let condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true))
let condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
let unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()

clauses.append(
Expand All @@ -95,14 +95,14 @@ extension Parser {
switch match {
case .poundElseif:
(unexpectedBeforePound, pound) = self.eat(handle)
condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true))
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()
case .poundElse:
(unexpectedBeforePound, pound) = self.eat(handle)
if let ifToken = self.consume(if: .init(.if, allowAtStartOfLine: false)) {
unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, ifToken, arena: self.arena)
pound = self.missingToken(.poundElseif)
condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true))
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
} else {
condition = nil
}
Expand All @@ -115,7 +115,7 @@ extension Parser {
}
unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, elif, arena: self.arena)
pound = self.missingToken(.poundElseif)
condition = RawExprSyntax(self.parseSequenceExpression(.basic, forDirective: true))
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()
} else {
break LOOP
Expand Down
Loading