diff --git a/src/cpp/cpp.test.ts b/src/cpp/cpp.test.ts index b31a89ec..e1aa2d99 100644 --- a/src/cpp/cpp.test.ts +++ b/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' }] + } ] ]); diff --git a/src/cpp/cpp.ts b/src/cpp/cpp.ts index d0c29f90..ac2ff50c 100644 --- a/src/cpp/cpp.ts +++ b/src/cpp/cpp.ts @@ -298,7 +298,7 @@ export const language = { { 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 = { [/[a-zA-Z0-9_]+/, 'annotation'], [/[,:]/, 'delimiter'], [/[()]/, '@brackets'], - [/\]\]/, { token: 'annotation', next: '@pop' }] + [/\]\s*\]/, { token: 'annotation', next: '@pop' }] ], include: [