From a6eae04888c8e48c112346d5eae266cee3749590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Sat, 20 Jul 2024 09:44:18 +0200 Subject: [PATCH 1/2] Try to update syntax highlighting --- src/effekt-syntax.ts | 54 ++++++++++++++++++++++++++--------------- src/highlight-effekt.js | 40 +++--------------------------- 2 files changed, 39 insertions(+), 55 deletions(-) diff --git a/src/effekt-syntax.ts b/src/effekt-syntax.ts index d04ac24..776661b 100644 --- a/src/effekt-syntax.ts +++ b/src/effekt-syntax.ts @@ -5,48 +5,51 @@ import ITheme = monaco.editor.IStandaloneThemeData; export const syntax = { // defaultToken: 'invalid', + tokenPostfix: '.effekt', keywords: [ 'module', 'import', 'def', 'val', 'var', 'effect', 'type', 'match', 'case', 'record', 'extern', 'include', 'resume', 'with', 'if', 'try', 'else', 'do', 'handle', 'while', 'fun', 'region', 'in', 'new', - 'box', 'unbox', 'interface', 'resource', 'and', 'is', 'namespace' + 'box', 'unbox', 'interface', 'resource', 'and', 'is', 'namespace', + 'return', 'as' ], definitionKeywords: [ - 'def', 'type', 'effect' + 'def', 'type', 'effect', 'val', 'var', 'extern', 'fun', 'interface', 'resource', 'namespace' ], literals: ['true', 'false'], operators: [ - '=', '>', '<', '!', '~', '?', ':', '==', '<=', '>=', '!=', - '&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%', - '<<', '>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=', '^=', - '%=', '<<=', '>>=', '>>>=' + '=', + ':', + '>', '<', '==', '<=', '>=', '!=', + '&&', '||', + '++', + '+', '-', '*', '/', + '=>', '::' ], // we include these common regular expressions symbols: /[=>{ [/[{}()\[\]]/, '@brackets'], [/[<>](?!@symbols)/, '@brackets'], [/@symbols/, { cases: { '@operators': 'operator', - '@default' : '' } } ], + '@default': '' } } ], // numbers [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'], @@ -71,6 +74,7 @@ export const syntax = { // characters [/'[^\\']'/, 'string'], + [/(')(@escapes)(')/, ['string', 'string.escape', 'string']], [/'/, 'string.invalid'] ], @@ -81,13 +85,25 @@ export const syntax = { ], comment: [ - [/[^\/*]+/, 'comment' ] + [/[^\/*]+/, 'comment'], + [/\/\*/, 'comment', '@push'], + ["\\*/", 'comment', '@pop'], + [/[\/*]/, 'comment'] ], string: [ - [/[^\\"]+/, 'string'], - [/\\./, 'string.escape.invalid'], - [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ] + [/[^\\"$]+/, 'string'], + [/@escapes/, 'string.escape'], + [/\\./, 'string.escape.invalid'], + [/\$\{/, { token: 'delimiter.bracket', next: '@bracketCounting' }], + [/\$[a-z_][\w$]*/, 'variable'], + [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }] + ], + + bracketCounting: [ + [/\{/, 'delimiter.bracket', '@bracketCounting'], + [/\}/, 'delimiter.bracket', '@pop'], + { include: 'root' } ], whitespace: [ diff --git a/src/highlight-effekt.js b/src/highlight-effekt.js index 205dd0b..415016f 100644 --- a/src/highlight-effekt.js +++ b/src/highlight-effekt.js @@ -66,40 +66,9 @@ hljs.registerLanguage("effekt", function highlightEffekt(hljs) { relevance: 0 }; - var CLASS = { - className: 'class', - beginKeywords: 'class object trait type', - end: /[:={\[\n;]/, - excludeEnd: true, - contains: [ - { - beginKeywords: 'extends with', - relevance: 10 - }, - { - begin: /\[/, - end: /\]/, - excludeBegin: true, - excludeEnd: true, - relevance: 0, - contains: [TYPE] - }, - { - className: 'params', - begin: /\(/, - end: /\)/, - excludeBegin: true, - excludeEnd: true, - relevance: 0, - contains: [TYPE] - }, - NAME - ] - }; - - var METHOD = { + var DEFINITION = { className: 'function', - beginKeywords: 'def', + beginKeywords: 'def effect type val var extern fun interface resource namespace', end: /[:={\[(\n;]/, excludeEnd: true, contains: [NAME] @@ -108,7 +77,7 @@ hljs.registerLanguage("effekt", function highlightEffekt(hljs) { return { name: 'Effekt', keywords: { - literal: 'true false null', + literal: 'true false', keyword: 'module effect type def with val var if for while import return else case try match resume do record region in new interface let box unbox fun extern and is namespace' }, contains: [ @@ -117,8 +86,7 @@ hljs.registerLanguage("effekt", function highlightEffekt(hljs) { STRING, SYMBOL, TYPE, - METHOD, - CLASS, + DEFINITION, hljs.C_NUMBER_MODE, ANNOTATION ] From f298eae40ef17f3883d42903947e3601ed1c01aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Thu, 12 Sep 2024 14:02:41 +0200 Subject: [PATCH 2/2] Try fixing the syntax again --- src/effekt-syntax.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/effekt-syntax.ts b/src/effekt-syntax.ts index 776661b..1113690 100644 --- a/src/effekt-syntax.ts +++ b/src/effekt-syntax.ts @@ -59,6 +59,8 @@ export const syntax = { [/[<>](?!@symbols)/, '@brackets'], [/@symbols/, { cases: { '@operators': 'operator', '@default': '' } } ], + // strings + [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }], // numbers [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'], @@ -84,20 +86,26 @@ export const syntax = { [new RegExp(""),'','@pop'] ], - comment: [ - [/[^\/*]+/, 'comment'], - [/\/\*/, 'comment', '@push'], - ["\\*/", 'comment', '@pop'], - [/[\/*]/, 'comment'] + string: [ + [/[^\\"$]+/, 'string'], + [/@escapes/, 'string.escape'], + [/\\./, 'string.escape.invalid'], + [/\$\{/, { token: 'string.escape', next: '@stringInterpolation' }], + [/\$/, 'string'], + [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }] ], - string: [ - [/[^\\"$]+/, 'string'], - [/@escapes/, 'string.escape'], - [/\\./, 'string.escape.invalid'], - [/\$\{/, { token: 'delimiter.bracket', next: '@bracketCounting' }], - [/\$[a-z_][\w$]*/, 'variable'], - [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }] + stringInterpolation: [ + [/\$\{/, 'delimiter.bracket', '@stringInterpolation'], + [/\}/, 'delimiter.bracket', '@pop'], + { include: 'root' } + ], + + comment: [ + [/[^\/*]+/, 'comment'], + [/\/\*/, 'comment', '@push'], + [/\*\//, 'comment', '@pop'], + [/[\/*]/, 'comment'] ], bracketCounting: [