From 9961f06110429131dedb9bb15ab8437ea8e2cb58 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 12 Nov 2018 13:52:04 +0100 Subject: [PATCH] Fixes Microsoft/monaco-editor#1170 --- src/python/python.test.ts | 63 +++++++++++++++++++++++++++++++++++++++ src/python/python.ts | 15 +++++----- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/python/python.test.ts b/src/python/python.test.ts index f4e9ea9d..f25c2028 100644 --- a/src/python/python.test.ts +++ b/src/python/python.test.ts @@ -92,6 +92,69 @@ testTokenization('python', [ ] }], + // https://github.com/Microsoft/monaco-editor/issues/1170 + [{ + line: 'def f():', + tokens: [ + { startIndex: 0, type: 'keyword.python' }, + { startIndex: 3, type: 'white.python' }, + { startIndex: 4, type: 'identifier.python' }, + { startIndex: 5, type: 'delimiter.parenthesis.python' }, + { startIndex: 7, type: 'delimiter.python' }, + ] + }, { + line: ' """multi', + tokens: [ + { startIndex: 0, type: 'white.python' }, + { startIndex: 3, type: 'string.python' }, + ] + }, { + line: ' line', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' comment', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' """ + """', + tokens: [ + { startIndex: 0, type: 'string.python' }, + { startIndex: 6, type: 'white.python' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'white.python' }, + { startIndex: 9, type: 'string.python' }, + ] + }, { + line: ' another', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' multi', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' line', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' comment"""', + tokens: [ + { startIndex: 0, type: 'string.python' }, + ] + }, { + line: ' code', + tokens: [ + { startIndex: 0, type: 'white.python' }, + { startIndex: 3, type: 'identifier.python' }, + ] + }], + // Numbers [{ line: '0xAcBFd', diff --git a/src/python/python.ts b/src/python/python.ts index 90f624ca..87112bf1 100644 --- a/src/python/python.ts +++ b/src/python/python.ts @@ -215,19 +215,20 @@ export const language = { whitespace: [ [/\s+/, 'white'], [/(^#.*$)/, 'comment'], - [/('''.*''')|(""".*""")/, 'string'], - [/'''.*$/, 'string', '@endDocString'], - [/""".*$/, 'string', '@endDblDocString'] + [/'''/, 'string', '@endDocString'], + [/"""/, 'string', '@endDblDocString'] ], endDocString: [ + [/[^']+/, 'string'], [/\\'/, 'string'], - [/.*'''/, 'string', '@popall'], - [/.*$/, 'string'] + [/'''/, 'string', '@popall'], + [/'/, 'string'] ], endDblDocString: [ + [/[^"]+/, 'string'], [/\\"/, 'string'], - [/.*"""/, 'string', '@popall'], - [/.*$/, 'string'] + [/"""/, 'string', '@popall'], + [/"/, 'string'] ], // Recognize hex, negatives, decimals, imaginaries, longs, and scientific notation