From 51df390edc83e6e7496e172edc3743b1d6726b71 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Wed, 7 Mar 2018 15:36:57 -0800 Subject: [PATCH] Fix microsoft/monaco-editor#703. c++ 11 raw string literal. --- src/cpp.ts | 15 +++++++++++++++ test/cpp.test.ts | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/cpp.ts b/src/cpp.ts index fe8614dc..799e1bdc 100644 --- a/src/cpp.ts +++ b/src/cpp.ts @@ -240,10 +240,14 @@ export const language = { escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, integersuffix: /(ll|LL|u|U|l|L)?(ll|LL|u|U|l|L)?/, floatsuffix: /[fFlL]?/, + encoding: /u|u8|U|L/, // The main tokenizer for our languages tokenizer: { root: [ + // C++ 11 Raw String + [/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: 'string.raw.begin', next: '@raw.$1' }], + // identifiers and keywords [/[a-zA-Z_]\w*/, { cases: { @@ -318,5 +322,16 @@ export const language = { [/\\./, 'string.escape.invalid'], [/"/, 'string', '@pop'] ], + + raw: [ + [/(.*)(\))(?:([^ ()\\\t]*))(\")/, { + cases: { + '$3==$S2': ['string.raw', 'string.raw.end', 'string.raw.end', { token: 'string.raw.end', next: '@pop' }], + '@default': ['string.raw', 'string.raw', 'string.raw', 'string.raw'] + } + } + ], + [/.*/, 'string.raw'] + ] }, }; diff --git a/test/cpp.test.ts b/test/cpp.test.ts index 9eb51ab5..043f12b5 100644 --- a/test/cpp.test.ts +++ b/test/cpp.test.ts @@ -776,5 +776,13 @@ testTokenization('cpp', [ { startIndex: 25, type: 'identifier.cpp' }, { startIndex: 26, type: 'delimiter.parenthesis.cpp' } ] + }, { + line: 'uR"V0G0N(abc)V0G0N"def', + tokens: [ + { startIndex: 0, type: 'string.raw.begin.cpp' }, + { startIndex: 9, type: 'string.raw.cpp' }, + { startIndex: 12, type: 'string.raw.end.cpp' }, + { startIndex: 19, type: 'identifier.cpp' } + ] }] ]);