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' }, }, }, }, 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/ 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 { 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': /```/, 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])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/, 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': [ 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;