Skip to content

Commit

Permalink
Fix microsoft/monaco-editor#858 C++ includes
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed May 3, 2018
1 parent 7195ea6 commit 7eb290d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/cpp/cpp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,19 @@ testTokenization('cpp', [
[{
line: '#include<iostream>',
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: '',
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ export const language = <ILanguage>{
// [[ attributes ]].
[/\[\[.*\]\]/, 'annotation'],

[/^\s*#include/, { token: 'keyword.directive.include', next: '@include' }],

// Preprocessor directive
[/^\s*#\s*\w+/, 'keyword'],

Expand Down Expand Up @@ -338,6 +340,11 @@ export const language = <ILanguage>{
}
],
[/.*/, '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'}]]
]
},
};

0 comments on commit 7eb290d

Please sign in to comment.