Skip to content

Generalize Lexeme State into Flags #805

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 2 commits into from
Sep 16, 2022
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
12 changes: 9 additions & 3 deletions Sources/SwiftParser/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,8 @@ extension Parser {
/// Parse open quote.
let openQuote = self.parseStringLiteralQuote(
at: openDelimiter != nil ? .leadingRaw : .leading,
text: text
text: text,
wantsMultiline: self.currentToken.isMultilineStringLiteral
) ?? RawTokenSyntax(missing: .stringQuote, arena: arena)
if !openQuote.isMissing {
text = text.dropFirst(openQuote.tokenText.count)
Expand All @@ -1078,7 +1079,8 @@ extension Parser {
/// Parse close quote.
let closeQuote = self.parseStringLiteralQuote(
at: openDelimiter != nil ? .trailingRaw : .trailing,
text: text
text: text,
wantsMultiline: self.currentToken.isMultilineStringLiteral
) ?? RawTokenSyntax(missing: openQuote.tokenKind, arena: arena)
if !closeQuote.isMissing {
text = text.dropFirst(closeQuote.tokenText.count)
Expand Down Expand Up @@ -1209,7 +1211,8 @@ extension Parser {

mutating func parseStringLiteralQuote(
at position: QuotePosition,
text: Slice<SyntaxText>
text: Slice<SyntaxText>,
wantsMultiline: Bool
) -> RawTokenSyntax? {
// Single quote. We only support single line literal.
if let first = text.first, first == UInt8(ascii: "'") {
Expand All @@ -1223,6 +1226,9 @@ extension Parser {
while index < text.endIndex && text[index] == UInt8(ascii: "\"") {
quoteCount += 1
index = text.index(after: index)
guard wantsMultiline else {
break
}
}

// Empty single line string. Return only the first quote.
Expand Down
Loading