From 27e64480481b6bfcc06e68c968cd940cd23aad96 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 12:31:05 +0200 Subject: [PATCH 1/7] [C] Fix transformation bug: `macro` should be inserted before `string` --- src/languages/c.ts | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/languages/c.ts b/src/languages/c.ts index 1ba059b658..1c30b389a4 100644 --- a/src/languages/c.ts +++ b/src/languages/c.ts @@ -37,48 +37,48 @@ export default { $insertBefore: { 'string': { char, - }, - 'macro': { - // allow for multiline macro definitions - // spaces after the # character compile fine with gcc - pattern: - /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, - lookbehind: true, - greedy: true, - alias: 'property', - inside: { - 'string': [ - { - // highlight the path of the include statement as a string - pattern: /^(#\s*include\s*)<[^>]+>/, + 'macro': { + // allow for multiline macro definitions + // spaces after the # character compile fine with gcc + pattern: + /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, + lookbehind: true, + greedy: true, + alias: 'property', + inside: { + 'string': [ + { + // highlight the path of the include statement as a string + pattern: /^(#\s*include\s*)<[^>]+>/, + lookbehind: true, + }, + string, + ], + 'char': char, + 'comment': comment, + 'macro-name': [ + { + pattern: /(^#\s*define\s+)\w+\b(?!\()/i, + lookbehind: true, + }, + { + pattern: /(^#\s*define\s+)\w+\b(?=\()/i, + lookbehind: true, + alias: 'function', + }, + ], + // highlight macro directives as keywords + 'directive': { + pattern: /^(#\s*)[a-z]+/, lookbehind: true, + alias: 'keyword', }, - string, - ], - 'char': char, - 'comment': comment, - 'macro-name': [ - { - pattern: /(^#\s*define\s+)\w+\b(?!\()/i, - lookbehind: true, + 'directive-hash': /^#/, + 'punctuation': /##|\\(?=[\r\n])/, + 'expression': { + pattern: /\S[\s\S]*/, + inside: { $rest: 'c' }, }, - { - pattern: /(^#\s*define\s+)\w+\b(?=\()/i, - lookbehind: true, - alias: 'function', - }, - ], - // highlight macro directives as keywords - 'directive': { - pattern: /^(#\s*)[a-z]+/, - lookbehind: true, - alias: 'keyword', - }, - 'directive-hash': /^#/, - 'punctuation': /##|\\(?=[\r\n])/, - 'expression': { - pattern: /\S[\s\S]*/, - inside: { $rest: 'c' }, }, }, }, From fb20631ab8183e4549ea6fa1661bd7a52a772853 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 12:47:56 +0200 Subject: [PATCH 2/7] [F#] Specify the base language --- src/languages/fsharp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/fsharp.ts b/src/languages/fsharp.ts index c6910bd5a9..4cec3341cd 100644 --- a/src/languages/fsharp.ts +++ b/src/languages/fsharp.ts @@ -4,7 +4,7 @@ import type { LanguageProto } from '../types'; export default { id: 'fsharp', alias: 'f#', - require: clike, + base: clike, optional: 'markup', grammar ({ languages }) { return { From 2abad7b87662a97d48259604d31f28e346333beb Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 12:48:34 +0200 Subject: [PATCH 3/7] [extend] Deeply nested objects can be `undefined` --- src/util/extend.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/extend.ts b/src/util/extend.ts index 89e41458e5..b0490e8232 100644 --- a/src/util/extend.ts +++ b/src/util/extend.ts @@ -64,7 +64,7 @@ export function extend (base: Grammar, grammar: Grammar): Grammar { } } else if (relToken) { - lang[all][relToken][tokenName] = token; + (lang[all][relToken] ??= {})[tokenName] = token; } else { lang[tokenName] = token; From 3cbeeea30a388be2c6f34685569c9041c7466bec Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 12:51:25 +0200 Subject: [PATCH 4/7] [C#] Specify the base language + remove unused imports --- src/languages/csharp.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/languages/csharp.ts b/src/languages/csharp.ts index 548f05ff02..e8234abd3d 100644 --- a/src/languages/csharp.ts +++ b/src/languages/csharp.ts @@ -1,4 +1,3 @@ -import { insertBefore } from '../util/insert'; import clike from './clike'; import type { LanguageProto } from '../types'; @@ -33,7 +32,7 @@ function nested (pattern: string, depthLog2: number) { export default { id: 'csharp', - require: clike, + base: clike, alias: ['c#', 'cs', 'dotnet'], grammar ({ languages }) { // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ From 9a7c02cde648f1a6616f3a1d921fbe5ba8e508a1 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 12:59:36 +0200 Subject: [PATCH 5/7] [PHP] Add missed tokens --- src/languages/php.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/languages/php.ts b/src/languages/php.ts index f36651085e..81783fa44a 100644 --- a/src/languages/php.ts +++ b/src/languages/php.ts @@ -318,6 +318,7 @@ export default { const embedded = embeddedIn('markup'); return { + ...php, 'php': { pattern: /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/, From 4d36fc31ddf8f712f97f9339af482928c087faa0 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 14:32:59 +0200 Subject: [PATCH 6/7] [VB.NET] Fix language definition --- src/languages/vbnet.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/languages/vbnet.ts b/src/languages/vbnet.ts index 2cede4693d..0fd8045824 100644 --- a/src/languages/vbnet.ts +++ b/src/languages/vbnet.ts @@ -11,11 +11,8 @@ export default { pattern: /'''.*/, greedy: true, alias: 'comment', - // TODO do better - get inside () { - if (languages.markup) { - return languages.markup.tag; - } + inside: { + 'tag': languages.markup?.tag, }, }, 'comment': [ From b15d510406d252a3a5c48e3aa49ca95225c93842 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Mon, 26 May 2025 14:44:02 +0200 Subject: [PATCH 7/7] [MD] Correctly capture the language code --- src/languages/markdown.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/markdown.ts b/src/languages/markdown.ts index 97e7ff650d..a6af63c4f4 100644 --- a/src/languages/markdown.ts +++ b/src/languages/markdown.ts @@ -95,7 +95,7 @@ export default { // code block // ``` pattern: - /^```(?[a-z-]+).+(?:\n|\r\n?)(?[\s\S]*)?(?:\n|\r\n?)```$/i, + /^```(?[a-z-]+)(?:.+)?(?:\n|\r\n?)(?[\s\S]*)?(?:\n|\r\n?)```$/i, inside: { 'code-block': groups => groups.codeLanguage, 'punctuation': /```/,