@@ -72,10 +72,10 @@ final class RegexLiteralTests: XCTestCase {
72
72
func testUnterminated2( ) {
73
73
assertParse (
74
74
#"""
75
- 1️⃣/
75
+ /1️⃣
76
76
"""# ,
77
77
diagnostics: [
78
- DiagnosticSpec ( message: " extraneous code '/' at top level " )
78
+ DiagnosticSpec ( message: " expected '/' to end regex literal " )
79
79
]
80
80
)
81
81
}
@@ -358,10 +358,10 @@ final class RegexLiteralTests: XCTestCase {
358
358
func testOpeningSpace1( ) {
359
359
assertParse (
360
360
"""
361
- 1️⃣/ a/
361
+ /1️⃣ a/
362
362
""" ,
363
363
diagnostics: [
364
- DiagnosticSpec ( message: " extraneous code '/ a/' at top level " )
364
+ DiagnosticSpec ( message: " bare slash regex literal may not start with space " )
365
365
]
366
366
)
367
367
}
@@ -418,10 +418,10 @@ final class RegexLiteralTests: XCTestCase {
418
418
func testOpeningAndClosingSpace1( ) {
419
419
assertParse (
420
420
"""
421
- 1️⃣/ /
421
+ /1️⃣ /
422
422
""" ,
423
423
diagnostics: [
424
- DiagnosticSpec ( message: " extraneous code '/ /' at top level " )
424
+ DiagnosticSpec ( message: " bare slash regex literal may not start with space " )
425
425
]
426
426
)
427
427
}
@@ -448,10 +448,10 @@ final class RegexLiteralTests: XCTestCase {
448
448
func testOpeningAndClosingSpace4( ) {
449
449
assertParse (
450
450
"""
451
- 1️⃣/ /
451
+ /1️⃣ /
452
452
""" ,
453
453
diagnostics: [
454
- DiagnosticSpec ( message: " extraneous code '/ /' at top level " )
454
+ DiagnosticSpec ( message: " bare slash regex literal may not start with space " )
455
455
]
456
456
)
457
457
}
@@ -911,6 +911,221 @@ final class RegexLiteralTests: XCTestCase {
911
911
)
912
912
}
913
913
914
+ func testBinOpDisambiguation51( ) {
915
+ // Unapplied operators, not regex.
916
+ assertParse (
917
+ """
918
+ foo(a: /, /)
919
+ """ ,
920
+ substructure: Syntax (
921
+ TupleExprElementListSyntax ( [
922
+ . init(
923
+ label: " a " ,
924
+ colon: . colonToken( ) ,
925
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) ) ,
926
+ trailingComma: . commaToken( )
927
+ ) ,
928
+ . init(
929
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
930
+ ) ,
931
+ ] )
932
+ )
933
+ )
934
+ }
935
+
936
+ func testBinOpDisambiguation52( ) {
937
+ // Unapplied operators, not regex.
938
+ assertParse (
939
+ """
940
+ foo(a, /, /)
941
+ """ ,
942
+ substructure: Syntax (
943
+ TupleExprElementListSyntax ( [
944
+ . init(
945
+ expression: IdentifierExprSyntax ( identifier: " a " ) ,
946
+ trailingComma: . commaToken( )
947
+ ) ,
948
+ . init(
949
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) ) ,
950
+ trailingComma: . commaToken( )
951
+ ) ,
952
+ . init(
953
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
954
+ ) ,
955
+ ] )
956
+ )
957
+ )
958
+ }
959
+
960
+ func testBinOpDisambiguation53( ) {
961
+ // Unapplied operators, not regex.
962
+ assertParse (
963
+ """
964
+ foo(a, ^/, /)
965
+ """ ,
966
+ substructure: Syntax (
967
+ TupleExprElementListSyntax ( [
968
+ . init(
969
+ expression: IdentifierExprSyntax ( identifier: " a " ) ,
970
+ trailingComma: . commaToken( )
971
+ ) ,
972
+ . init(
973
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " ^/ " ) ) ,
974
+ trailingComma: . commaToken( )
975
+ ) ,
976
+ . init(
977
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
978
+ ) ,
979
+ ] )
980
+ )
981
+ )
982
+ }
983
+
984
+ func testBinOpDisambiguation54( ) {
985
+ // Unapplied operators, not regex.
986
+ assertParse (
987
+ """
988
+ foo(a: ^/, /)
989
+ """ ,
990
+ substructure: Syntax (
991
+ TupleExprElementListSyntax ( [
992
+ . init(
993
+ label: " a " ,
994
+ colon: . colonToken( ) ,
995
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " ^/ " ) ) ,
996
+ trailingComma: . commaToken( )
997
+ ) ,
998
+ . init(
999
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1000
+ ) ,
1001
+ ] )
1002
+ )
1003
+ )
1004
+ }
1005
+
1006
+ func testBinOpDisambiguation55( ) {
1007
+ // Unapplied operators, not regex.
1008
+ assertParse (
1009
+ """
1010
+ foo(^/, /)
1011
+ """ ,
1012
+ substructure: Syntax (
1013
+ TupleExprElementListSyntax ( [
1014
+ . init(
1015
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " ^/ " ) ) ,
1016
+ trailingComma: . commaToken( )
1017
+ ) ,
1018
+ . init(
1019
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1020
+ ) ,
1021
+ ] )
1022
+ )
1023
+ )
1024
+ }
1025
+
1026
+ func testBinOpDisambiguation56( ) {
1027
+ // Unapplied operators, not regex.
1028
+ assertParse (
1029
+ """
1030
+ (^/, /)
1031
+ """ ,
1032
+ substructure: Syntax (
1033
+ TupleExprElementListSyntax ( [
1034
+ . init(
1035
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " ^/ " ) ) ,
1036
+ trailingComma: . commaToken( )
1037
+ ) ,
1038
+ . init(
1039
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1040
+ ) ,
1041
+ ] )
1042
+ )
1043
+ )
1044
+ }
1045
+
1046
+ func testBinOpDisambiguation57( ) {
1047
+ // Unapplied operators, not regex.
1048
+ assertParse (
1049
+ """
1050
+ (/, /)
1051
+ """ ,
1052
+ substructure: Syntax (
1053
+ TupleExprElementListSyntax ( [
1054
+ . init(
1055
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) ) ,
1056
+ trailingComma: . commaToken( )
1057
+ ) ,
1058
+ . init(
1059
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1060
+ ) ,
1061
+ ] )
1062
+ )
1063
+ )
1064
+ }
1065
+
1066
+ func testBinOpDisambiguation58( ) {
1067
+ // Unapplied operators, not regex.
1068
+ assertParse (
1069
+ """
1070
+ x[/, /]
1071
+ """ ,
1072
+ substructure: Syntax (
1073
+ TupleExprElementListSyntax ( [
1074
+ . init(
1075
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) ) ,
1076
+ trailingComma: . commaToken( )
1077
+ ) ,
1078
+ . init(
1079
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1080
+ ) ,
1081
+ ] )
1082
+ )
1083
+ )
1084
+ }
1085
+
1086
+ func testBinOpDisambiguation59( ) {
1087
+ // Unapplied operators, not regex.
1088
+ assertParse (
1089
+ """
1090
+ x[^/, /]
1091
+ """ ,
1092
+ substructure: Syntax (
1093
+ TupleExprElementListSyntax ( [
1094
+ . init(
1095
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " ^/ " ) ) ,
1096
+ trailingComma: . commaToken( )
1097
+ ) ,
1098
+ . init(
1099
+ expression: IdentifierExprSyntax ( identifier: . binaryOperator( " / " ) )
1100
+ ) ,
1101
+ ] )
1102
+ )
1103
+ )
1104
+ }
1105
+
1106
+ func testBinOpDisambiguation60( ) {
1107
+ // Invalid. We can't confidently lex as a regex (as the lexer thinks it
1108
+ // could be a subscript), so we get a parser error.
1109
+ assertParse (
1110
+ """
1111
+ [1️⃣/, /]
1112
+ """ ,
1113
+ diagnostics: [
1114
+ DiagnosticSpec ( message: " unexpected code '/, /' in array " )
1115
+ ]
1116
+ )
1117
+ }
1118
+
1119
+ func testBinOpDisambiguation61( ) {
1120
+ // Fine if there's no trailing space though.
1121
+ assertParse (
1122
+ """
1123
+ [/,/]
1124
+ """ ,
1125
+ substructure: Syntax ( RegexLiteralExprSyntax ( regexPattern: . regexLiteralPattern( " , " ) ) )
1126
+ )
1127
+ }
1128
+
914
1129
func testPrefixOpSplitting1( ) {
915
1130
assertParse (
916
1131
"""
0 commit comments