From 93f8458ba0dceff2fa12b8eb209b5055e8817b73 Mon Sep 17 00:00:00 2001 From: skacurt Date: Sat, 9 May 2020 01:51:10 +0300 Subject: [PATCH] [vb] fix string literals aims to close microsoft/monaco-editor#1958 and microsoft/monaco-editor#1941 --- src/vb/vb.test.ts | 85 +++++++++++++++++++++++++++++++++++++++++++++-- src/vb/vb.ts | 10 +++--- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/vb/vb.test.ts b/src/vb/vb.test.ts index f847a92e..8f71ac7c 100644 --- a/src/vb/vb.test.ts +++ b/src/vb/vb.test.ts @@ -289,18 +289,95 @@ testTokenization('vb', [ { startIndex: 8, type: '' }, { startIndex: 9, type: 'delimiter.vb' }, { startIndex: 10, type: '' }, - { startIndex: 11, type: 'string.vb' } + { startIndex: 11, type: 'string.quote.vb' }, + { startIndex: 12, type: 'string.vb' }, + { startIndex: 18, type: 'string.quote.vb' } ] }], [{ line: '"use strict";', tokens: [ - { startIndex: 0, type: 'string.vb' }, + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 11, type: 'string.quote.vb' }, { startIndex: 12, type: 'delimiter.vb' } ] }], + [{ + line: '"a""b"', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 2, type: 'string.escape.vb' }, + { startIndex: 4, type: 'string.vb' }, + { startIndex: 5, type: 'string.quote.vb' } + ] + }, { + line: '"a““b"', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 2, type: 'string.escape.vb' }, + { startIndex: 4, type: 'string.vb' }, + { startIndex: 5, type: 'string.quote.vb' } + ] + }, { + line: '"a””b"', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 2, type: 'string.escape.vb' }, + { startIndex: 4, type: 'string.vb' }, + { startIndex: 5, type: 'string.quote.vb' } + ] + }], + + [{ + line: '"mixed quotes 1“', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }, { + line: '"mixed quotes 2”', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }, { + line: '“mixed quotes 3"', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }, { + line: '“mixed quotes 4”', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }, { + line: '”mixed quotes 5"', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }, { + line: '”mixed quotes 6“', + tokens: [ + { startIndex: 0, type: 'string.quote.vb' }, + { startIndex: 1, type: 'string.vb' }, + { startIndex: 15, type: 'string.quote.vb' } + ] + }], + // Tags [{ line: 'Public Sub ToString()', @@ -445,12 +522,14 @@ testTokenization('vb', [ { startIndex: 5, type: '' }, { startIndex: 6, type: 'delimiter.vb' }, { startIndex: 7, type: '' }, - { startIndex: 8, type: 'string.vb' } + { startIndex: 8, type: 'string.quote.vb' }, + { startIndex: 9, type: 'string.vb' } ] }, { line: 'world"', tokens: [ { startIndex: 0, type: 'string.vb' }, + { startIndex: 5, type: 'string.quote.vb' } ] }], diff --git a/src/vb/vb.ts b/src/vb/vb.ts index 82c7e179..b738096d 100644 --- a/src/vb/vb.ts +++ b/src/vb/vb.ts @@ -124,7 +124,6 @@ export const language = { // we include these common regular expressions symbols: /[=>{ [/@symbols/, 'delimiter'], // strings - [/"/, 'string', '@string'], + [/["\u201c\u201d]/, { token: 'string.quote', next: '@string' }], ], @@ -179,10 +178,9 @@ export const language = { ], string: [ - [/[^\\"]+/, 'string'], - [/@escapes/, 'string.escape'], - [/\\./, 'string.escape.invalid'], - [/"C?/, 'string', '@pop'] + [/[^"\u201c\u201d]+/, 'string'], + [/["\u201c\u201d]{2}/, 'string.escape'], + [/["\u201c\u201d]C?/, { token: 'string.quote', next: '@pop' }] ], }, };