diff --git a/README.md b/README.md index a62fba77..d84f09de 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed * apex * azcli * bat +* cameligo * clojure * coffee script * cpp diff --git a/scripts/bundle.js b/scripts/bundle.js index c9185650..42e87e1c 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -23,6 +23,7 @@ const BUNDLED_FILE_HEADER = [ bundleOne('monaco.contribution'); bundleOne('abap/abap'); bundleOne('bat/bat'); +bundleOne('cameligo/cameligo'), bundleOne('css/css'); bundleOne('coffee/coffee'); bundleOne('cpp/cpp'); diff --git a/src/cameligo/cameligo.contribution.ts b/src/cameligo/cameligo.contribution.ts new file mode 100644 index 00000000..31af8d16 --- /dev/null +++ b/src/cameligo/cameligo.contribution.ts @@ -0,0 +1,14 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { registerLanguage } from '../_.contribution'; + +registerLanguage({ + id: 'cameligo', + extensions: ['.mligo'], + aliases: ['Cameligo'], + loader: () => import('./cameligo') +}); diff --git a/src/cameligo/cameligo.test.ts b/src/cameligo/cameligo.test.ts new file mode 100644 index 00000000..864d9344 --- /dev/null +++ b/src/cameligo/cameligo.test.ts @@ -0,0 +1,140 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from '../test/testRunner'; + +testTokenization('cameligo', [ + + // Comments - single line + [{ + line: '//', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + [{ + line: ' // a comment', + tokens: [ + { startIndex: 0, type: 'white.cameligo' }, + { startIndex: 4, type: 'comment.cameligo' } + ] + }], + + [{ + line: '// a comment', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + [{ + line: '//sticky comment', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + // Comments - multi line (single line) + [{ + line: '(**)', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + [{ + line: ' (* a comment *)', + tokens: [ + { startIndex: 0, type: 'white.cameligo' }, + { startIndex: 4, type: 'comment.cameligo' } + ] + }], + + [{ + line: '(* a comment *)', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + [{ + line: '(*sticky comment*)', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }], + + // Comments - multi line (multi line) + [{ + line: '(* start of multiline comment ', + tokens: [ + { startIndex: 0, type: 'comment.cameligo' } + ] + }, { + line: 'a comment between curly', + tokens: [ + { startIndex: 0, type: 'comment.cameligo'} + ] + }, { + line: 'end of multiline comment*)', + tokens: [ + { startIndex: 0, type: 'comment.cameligo'} + ] + }], + + // Keywords + [{ + line: 'let check if Current.amount', + tokens: [ + { startIndex: 0, type: 'keyword.let.cameligo'}, + { startIndex: 3, type: 'white.cameligo'}, + { startIndex: 4, type: 'identifier.cameligo'}, + { startIndex: 9, type: 'white.cameligo'}, + { startIndex: 10, type: 'keyword.if.cameligo'}, + { startIndex: 12, type: 'white.cameligo'}, + { startIndex: 13, type: 'keyword.current.cameligo'}, + { startIndex: 20, type: 'delimiter.cameligo'}, + { startIndex: 21, type: 'identifier.cameligo'}, + ] + }], + + // Numbers + [{ + line: '0', + tokens: [ + { startIndex: 0, type: 'number.cameligo'} + ] + }], + [{ + line: '0;', + tokens: [ + { startIndex: 0, type: 'number.cameligo'}, + { startIndex: 1, type: 'delimiter.cameligo'} + ] + }], + [{ + line: '2.4', + tokens: [ + { startIndex: 0, type: 'number.float.cameligo'} + ] + }], + [{ + line: '2.4;', + tokens: [ + { startIndex: 0, type: 'number.float.cameligo'}, + { startIndex: 3, type: 'delimiter.cameligo'} + ] + }], + [{ + line: '$123FF', + tokens: [ + { startIndex: 0, type: 'number.hex.cameligo'} + ] + }] + +]); diff --git a/src/cameligo/cameligo.ts b/src/cameligo/cameligo.ts new file mode 100644 index 00000000..8bf39923 --- /dev/null +++ b/src/cameligo/cameligo.ts @@ -0,0 +1,131 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + comments: { + lineComment: '//', + blockComment: ['(*', '*)'], + }, + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'], + ['<', '>'], + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '<', close: '>' }, + { open: '\'', close: '\'' }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '<', close: '>' }, + { open: '\'', close: '\'' }, + ] +}; + +export const language = { + defaultToken: '', + tokenPostfix: '.cameligo', + ignoreCase: true, + + brackets: [ + { open: '{', close: '}', token: 'delimiter.curly' }, + { open: '[', close: ']', token: 'delimiter.square' }, + { open: '(', close: ')', token: 'delimiter.parenthesis' }, + { open: '<', close: '>', token: 'delimiter.angle' } + ], + + keywords: [ + 'abs', 'begin', 'Bytes', 'Crypto', 'Current', 'else', 'end', 'failwith', + 'false', 'fun', 'if', 'in', 'let', 'let%entry', 'let%init', 'List', 'list', + 'Map', 'map', 'match', 'match%nat', 'mod', 'not', 'operation', 'Operation', 'of', + 'Set', 'set', 'sender', 'source', 'String', 'then', 'true', 'type', 'with', + ], + + typeKeywords: [ + 'int', 'unit', 'string', 'tz', + ], + + operators: [ + '=', '>', '<', '<=', '>=', '<>', ':', ':=', 'and', 'mod', 'or', + '+', '-', '*', '/', '@', '&', '^', '%', '->', '<-' + ], + + // we include these common regular expressions + symbols: /[=><:@\^&|+\-*\/\^%]+/, + + // The main tokenizer for our languages + tokenizer: { + root: [ + // identifiers and keywords + [/[a-zA-Z_][\w]*/, { + cases: { + '@keywords': { token: 'keyword.$0' }, + '@default': 'identifier' + } + }], + + // whitespace + { include: '@whitespace' }, + + // delimiters and operators + [/[{}()\[\]]/, '@brackets'], + [/[<>](?!@symbols)/, '@brackets'], + [/@symbols/, { + cases: { + '@operators': 'delimiter', + '@default': '' + } + }], + + // numbers + [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'], + [/\$[0-9a-fA-F]{1,16}/, 'number.hex'], + [/\d+/, 'number'], + + // delimiter: after number because of .\d floats + [/[;,.]/, 'delimiter'], + + // strings + [/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string + [/'/, 'string', '@string'], + + // characters + [/'[^\\']'/, 'string'], + [/'/, 'string.invalid'], + [/\#\d+/,'string'] + ], + /* */ + + comment: [ + [/[^\(\*]+/, 'comment' ], + //[/\(\*/, 'comment', '@push' ], // nested comment not allowed :-( + [/\*\)/, 'comment', '@pop' ], + [/\(\*/, 'comment' ] + ], + + string: [ + [/[^\\']+/, 'string'], + [/\\./, 'string.escape.invalid'], + [/'/, { token: 'string.quote', bracket: '@close', next: '@pop' } ] + ], + + whitespace: [ + [/[ \t\r\n]+/, 'white'], + [/\(\*/, 'comment', '@comment' ], + [/\/\/.*$/, 'comment'], + ], + }, +}; diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 566cb224..2b117fd6 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -6,6 +6,7 @@ import './abap/abap.contribution'; import './bat/bat.contribution'; +import './cameligo/cameligo.contribution'; import './coffee/coffee.contribution'; import './cpp/cpp.contribution'; import './csharp/csharp.contribution'; diff --git a/test/setup.js b/test/setup.js index dfccf0aa..d877db15 100644 --- a/test/setup.js +++ b/test/setup.js @@ -29,6 +29,7 @@ define(['require'], function () { 'release/dev/apex/apex.test', 'release/dev/azcli/azcli.test', 'release/dev/bat/bat.test', + 'release/dev/cameligo/cameligo.test', 'release/dev/clojure/clojure.test', 'release/dev/coffee/coffee.test', 'release/dev/cpp/cpp.test',