From a9ba86ce031b83c23fe377289327c0b87c3b598b Mon Sep 17 00:00:00 2001 From: evakili Date: Sat, 20 Jan 2018 15:05:00 +0330 Subject: [PATCH] whitespaces after # are allowed in C++ preprocessor statements --- src/cpp.ts | 2 +- test/cpp.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/cpp.ts b/src/cpp.ts index 9d4b2baf..fe8614dc 100644 --- a/src/cpp.ts +++ b/src/cpp.ts @@ -259,7 +259,7 @@ export const language = { [/\[\[.*\]\]/, 'annotation'], // Preprocessor directive - [/^\s*#\w+/, 'keyword'], + [/^\s*#\s*\w+/, 'keyword'], // delimiters and operators [/[{}()\[\]]/, '@brackets'], diff --git a/test/cpp.test.ts b/test/cpp.test.ts index 28a87d1f..9eb51ab5 100644 --- a/test/cpp.test.ts +++ b/test/cpp.test.ts @@ -747,5 +747,34 @@ testTokenization('cpp', [ tokens: [ { startIndex: 0, type: 'keyword.cpp' } ] + }, { + line: '# ifdef VAR', + tokens: [ + { startIndex: 0, type: 'keyword.cpp' }, + { startIndex: 10, type: '' }, + { startIndex: 11, type: 'identifier.cpp' } + ] + }, { + line: '# define SUM(A,B) (A) + (B)', + tokens: [ + { startIndex: 0, type: 'keyword.cpp' }, + { startIndex: 8, type: '' }, + { startIndex: 9, type: 'identifier.cpp' }, + { startIndex: 12, type: 'delimiter.parenthesis.cpp' }, + { startIndex: 13, type: 'identifier.cpp' }, + { startIndex: 14, type: 'delimiter.cpp' }, + { startIndex: 15, type: 'identifier.cpp' }, + { startIndex: 16, type: 'delimiter.parenthesis.cpp' }, + { startIndex: 17, type: '' }, + { startIndex: 18, type: 'delimiter.parenthesis.cpp' }, + { startIndex: 19, type: 'identifier.cpp' }, + { startIndex: 20, type: 'delimiter.parenthesis.cpp' }, + { startIndex: 21, type: '' }, + { startIndex: 22, type: 'delimiter.cpp' }, + { startIndex: 23, type: '' }, + { startIndex: 24, type: 'delimiter.parenthesis.cpp' }, + { startIndex: 25, type: 'identifier.cpp' }, + { startIndex: 26, type: 'delimiter.parenthesis.cpp' } + ] }] ]);