瀏覽代碼

Fix microsoft/monaco-editor#703. c++ 11 raw string literal.

Peng Lyu 7 年之前
父節點
當前提交
51df390edc
共有 2 個文件被更改,包括 23 次插入0 次删除
  1. 15 0
      src/cpp.ts
  2. 8 0
      test/cpp.test.ts

+ 15 - 0
src/cpp.ts

@@ -240,10 +240,14 @@ export const language = <ILanguage>{
 	escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
 	integersuffix: /(ll|LL|u|U|l|L)?(ll|LL|u|U|l|L)?/,
 	floatsuffix: /[fFlL]?/,
+	encoding: /u|u8|U|L/,
 
 	// The main tokenizer for our languages
 	tokenizer: {
 		root: [
+			// C++ 11 Raw String
+			[/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: 'string.raw.begin', next: '@raw.$1' }],
+
 			// identifiers and keywords
 			[/[a-zA-Z_]\w*/, {
 				cases: {
@@ -318,5 +322,16 @@ export const language = <ILanguage>{
 			[/\\./, 'string.escape.invalid'],
 			[/"/, 'string', '@pop']
 		],
+
+		raw: [
+			[/(.*)(\))(?:([^ ()\\\t]*))(\")/, {
+					cases: {
+						'$3==$S2': ['string.raw', 'string.raw.end', 'string.raw.end', { token: 'string.raw.end', next: '@pop' }],
+						'@default': ['string.raw', 'string.raw', 'string.raw', 'string.raw']
+					}
+				}
+			],
+			[/.*/, 'string.raw']
+		]
 	},
 };

+ 8 - 0
test/cpp.test.ts

@@ -776,5 +776,13 @@ testTokenization('cpp', [
 			{ startIndex: 25, type: 'identifier.cpp' },
 			{ startIndex: 26, type: 'delimiter.parenthesis.cpp' }
 		]
+	}, {
+		line: 'uR"V0G0N(abc)V0G0N"def',
+		tokens: [
+			{ startIndex: 0, type: 'string.raw.begin.cpp' },
+			{ startIndex: 9, type: 'string.raw.cpp' },
+			{ startIndex: 12, type: 'string.raw.end.cpp' },
+			{ startIndex: 19, type: 'identifier.cpp' }
+		]
 	}]
 ]);