Support whitespace between annotation brackets

See compiler-explorer/compiler-explorer#880
This commit is contained in:
Matt Godbolt 2021-02-15 17:39:19 -06:00
parent 265d83f041
commit c8c2ebc277
2 changed files with 10 additions and 2 deletions

View file

@ -858,6 +858,7 @@ testTokenization('cpp', [
} }
], ],
// Annotations
[ [
{ {
line: '[[nodiscard]]', line: '[[nodiscard]]',
@ -906,5 +907,12 @@ testTokenization('cpp', [
{ startIndex: 8, type: 'delimiter.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' }]
}
] ]
]); ]);

View file

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