Skip to content

Commit d9fc0a8

Browse files
authored
Merge pull request #7062 from bitjammer/rdar-28457876-placeholder-operator-3.1
2 parents d8dcd8f + d5a27a4 commit d9fc0a8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/Parse/Lexer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,19 @@ static bool isRightBound(const char *tokEnd, bool isLeftBound,
678678
}
679679
}
680680

681+
static bool rangeContainsPlaceholderEnd(const char *CurPtr,
682+
const char *End) {
683+
while (CurPtr++ < End - 1) {
684+
if (*CurPtr== '\n') {
685+
return false;
686+
}
687+
if (CurPtr[0] == '#' && CurPtr[1] == '>') {
688+
return true;
689+
}
690+
}
691+
return false;
692+
}
693+
681694
/// lexOperatorIdentifier - Match identifiers formed out of punctuation.
682695
void Lexer::lexOperatorIdentifier() {
683696
const char *TokStart = CurPtr-1;
@@ -697,6 +710,10 @@ void Lexer::lexOperatorIdentifier() {
697710
// started with a '.'.
698711
if (*CurPtr == '.' && *TokStart != '.')
699712
break;
713+
if (Identifier::isEditorPlaceholder(StringRef(CurPtr, 2)) &&
714+
rangeContainsPlaceholderEnd(CurPtr + 2, BufferEnd)) {
715+
break;
716+
}
700717
} while (advanceIfValidContinuationOfOperator(CurPtr, BufferEnd));
701718

702719
if (CurPtr-TokStart > 2) {

test/IDE/structure_object_literals.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ struct I: _ExpressibleByImageLiteral {
1313

1414
// CHECK: <gvar>let <name>z</name>: I? = <object-literal-expression>#<name>imageLiteral</name>(<arg><name>resourceName</name>: "hello.png"</arg>)</object-literal-expression></gvar>
1515
let z: I? = #imageLiteral(resourceName: "hello.png")
16+
17+
func before() {}
18+
// CHECK-AFTER: <ffunc>func <name>before()</name> {}</ffunc>
19+
_ = .<#line#>
20+
_ = 1<#line
21+
_ = 1<#line#>
22+
_ = a.+<#file#>
23+
_ = x.<; <# #>;
24+
_ = 2.<#file(2)
25+
<##>
26+
x <##> y
27+
_ = .<#placeholder#>
28+
_ = #colorLiteral(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
29+
30+
.<# place #> #fileLiteral(resourceName: "sdfds") .<# holder #>
31+
.<##>#imageLiteral(resourceName: <# name #>)x.<##>
32+
33+
func after() {}
34+
// CHECK-AFTER: _ = <object-literal-expression>#<name>colorLiteral</name>(<arg><name>red</name>: 0.0</arg>, <arg><name>green</name>: 0.0</arg>, <arg><name>blue</name>: 0.0</arg>, <arg><name>alpha</name>: 1.0</arg>)</object-literal-expression>
35+
// CHECK-AFTER: .<# place #> <object-literal-expression>#<name>fileLiteral</name>(<arg><name>resourceName</name>: "sdfds"</arg>)</object-literal-expression> .<# holder #>
36+
// CHECK-AFTER: .<##><object-literal-expression>#<name>imageLiteral</name>(<arg><name>resourceName</name>: <# name #></arg>)</object-literal-expression>x.<##>
37+
// CHECK-AFTER: <ffunc>func <name>after()</name> {}</ffunc>
38+

0 commit comments

Comments
 (0)