Procházet zdrojové kódy

Support whitespace between annotation brackets

See compiler-explorer/compiler-explorer#880
Matt Godbolt před 4 roky
rodič
revize
c8c2ebc277
2 změnil soubory, kde provedl 10 přidání a 2 odebrání
  1. 8 0
      src/cpp/cpp.test.ts
  2. 2 2
      src/cpp/cpp.ts

+ 8 - 0
src/cpp/cpp.test.ts

@@ -858,6 +858,7 @@ testTokenization('cpp', [
 		}
 	],
 
+	// Annotations
 	[
 		{
 			line: '[[nodiscard]]',
@@ -906,5 +907,12 @@ testTokenization('cpp', [
 				{ startIndex: 8, type: 'delimiter.cpp' }
 			]
 		}
+	],
+	[
+		// We don't support newlines between annotation square brackets, but we do support other whitespace.
+		{
+			line: '[ [nodiscard] ]',
+			tokens: [{ startIndex: 0, type: 'annotation.cpp' }]
+		}
 	]
 ]);

+ 2 - 2
src/cpp/cpp.ts

@@ -298,7 +298,7 @@ export const language = <languages.IMonarchLanguage>{
 			{ include: '@whitespace' },
 
 			// [[ attributes ]].
-			[/\[\[/, { token: 'annotation', next: '@annotation' }],
+			[/\[\s*\[/, { token: 'annotation', next: '@annotation' }],
 
 			[/^\s*#include/, { token: 'keyword.directive.include', next: '@include' }],
 
@@ -390,7 +390,7 @@ export const language = <languages.IMonarchLanguage>{
 			[/[a-zA-Z0-9_]+/, 'annotation'],
 			[/[,:]/, 'delimiter'],
 			[/[()]/, '@brackets'],
-			[/\]\]/, { token: 'annotation', next: '@pop' }]
+			[/\]\s*\]/, { token: 'annotation', next: '@pop' }]
 		],
 
 		include: [