diff --git a/src/effekt-syntax.ts b/src/effekt-syntax.ts index d04ac24..1113690 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': '' } } ], + // strings + [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }], // numbers [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'], @@ -71,6 +76,7 @@ export const syntax = { // characters [/'[^\\']'/, 'string'], + [/(')(@escapes)(')/, ['string', 'string.escape', 'string']], [/'/, 'string.invalid'] ], @@ -80,14 +86,32 @@ export const syntax = { [new RegExp(""),'','@pop'] ], + string: [ + [/[^\\"$]+/, 'string'], + [/@escapes/, 'string.escape'], + [/\\./, 'string.escape.invalid'], + [/\$\{/, { token: 'string.escape', next: '@stringInterpolation' }], + [/\$/, 'string'], + [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }] + ], + + stringInterpolation: [ + [/\$\{/, 'delimiter.bracket', '@stringInterpolation'], + [/\}/, 'delimiter.bracket', '@pop'], + { include: 'root' } + ], + comment: [ - [/[^\/*]+/, 'comment' ] + [/[^\/*]+/, 'comment'], + [/\/\*/, 'comment', '@push'], + [/\*\//, 'comment', '@pop'], + [/[\/*]/, 'comment'] ], - string: [ - [/[^\\"]+/, 'string'], - [/\\./, 'string.escape.invalid'], - [/"/, { 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 ]