浏览代码

Add support for multiline strings in Swift

nrayburn 5 年之前
父节点
当前提交
28741d3741
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. 14 0
      src/swift/swift.test.ts
  2. 7 0
      src/swift/swift.ts

+ 14 - 0
src/swift/swift.test.ts

@@ -163,6 +163,20 @@ testTokenization('swift', [
 			{ startIndex: 60, type: 'string.quote.swift' } /* '"' */
 			{ startIndex: 60, type: 'string.quote.swift' } /* '"' */
 		]
 		]
 	}],
 	}],
+	// Multiline string
+	[{
+		line: '"""test"test', // Separate new lines into separate objects within this same array.
+		tokens: [
+			{ startIndex: 0, type: 'string.quote.swift' }, /* '"""' */
+			{ startIndex: 3, type: 'string.swift' } /* test"test */
+		]
+	}, {
+		line: ' keepsgoing"""',
+		tokens: [
+			{ startIndex: 0, type: 'string.swift' }, /* ' keepsgoing' */
+			{ startIndex: 11, type: 'string.quote.swift' } /* '"""' */
+		]
+	}],
 	// Method invocation/property accessor.
 	// Method invocation/property accessor.
 	[{
 	[{
 		line: '        let view = self.window!.contr as! UIView',
 		line: '        let view = self.window!.contr as! UIView',

+ 7 - 0
src/swift/swift.ts

@@ -83,6 +83,13 @@ export const language = <ILanguage>{
 			[/"""/, 'string.quote', '@endDblDocString']
 			[/"""/, 'string.quote', '@endDblDocString']
 		],
 		],
 
 
+		endDblDocString: [
+			[/[^"]+/, 'string'],
+			[/\\"/, 'string'],
+			[/"""/, 'string.quote', '@popall'],
+			[/"/, 'string']
+		],
+
 		symbol: [
 		symbol: [
 			[/[{}()\[\]]/, '@brackets'],
 			[/[{}()\[\]]/, '@brackets'],
 			[/[<>](?!@symbols)/, '@brackets'],
 			[/[<>](?!@symbols)/, '@brackets'],