From 7eb290dff49d83a998cab6b25a4d262cb6e0a956 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Thu, 3 May 2018 14:33:48 -0700 Subject: [PATCH] Fix microsoft/monaco-editor#858 C++ includes --- src/cpp/cpp.test.ts | 14 ++++++++------ src/cpp/cpp.ts | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cpp/cpp.test.ts b/src/cpp/cpp.test.ts index 27e8d9da..a06892f0 100644 --- a/src/cpp/cpp.test.ts +++ b/src/cpp/cpp.test.ts @@ -391,17 +391,19 @@ testTokenization('cpp', [ [{ line: '#include', tokens: [ - { startIndex: 0, type: 'keyword.cpp' }, - { startIndex: 8, type: 'delimiter.angle.cpp' }, - { startIndex: 9, type: 'identifier.cpp' }, - { startIndex: 17, type: 'delimiter.angle.cpp' } + { startIndex: 0, type: 'keyword.directive.include.cpp' }, + { startIndex: 8, type: 'keyword.directive.include.begin.cpp' }, + { startIndex: 9, type: 'string.include.identifier.cpp' }, + { startIndex: 17, type: 'keyword.directive.include.end.cpp' } ] }, { line: '#include "/path/to/my/file.h"', tokens: [ - { startIndex: 0, type: 'keyword.cpp' }, + { startIndex: 0, type: 'keyword.directive.include.cpp' }, { startIndex: 8, type: '' }, - { startIndex: 9, type: 'string.cpp' } + { startIndex: 9, type: 'keyword.directive.include.begin.cpp' }, + { startIndex: 10, type: 'string.include.identifier.cpp' }, + { startIndex: 28, type: 'keyword.directive.include.end.cpp' } ] }, { line: '', diff --git a/src/cpp/cpp.ts b/src/cpp/cpp.ts index 7e631cbc..7683f63e 100644 --- a/src/cpp/cpp.ts +++ b/src/cpp/cpp.ts @@ -268,6 +268,8 @@ export const language = { // [[ attributes ]]. [/\[\[.*\]\]/, 'annotation'], + [/^\s*#include/, { token: 'keyword.directive.include', next: '@include' }], + // Preprocessor directive [/^\s*#\s*\w+/, 'keyword'], @@ -338,6 +340,11 @@ export const language = { } ], [/.*/, 'string.raw'] + ], + + include: [ + [/(\s*)(<)([^<>]*)(>)/, ['', 'keyword.directive.include.begin', 'string.include.identifier', { token: 'keyword.directive.include.end', next: '@pop'}]], + [/(\s*)(")([^"]*)(")/, ['', 'keyword.directive.include.begin', 'string.include.identifier', { token: 'keyword.directive.include.end', next: '@pop'}]] ] }, };