Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #75 from mbykovskyy/master
Browse files Browse the repository at this point in the history
Adds cameligo language support
  • Loading branch information
alexdima committed Dec 16, 2019
2 parents 4370bf5 + c123d33 commit 998a8b2
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -8,6 +8,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed
* apex
* azcli
* bat
* cameligo
* clojure
* coffee script
* cpp
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.js
Expand Up @@ -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');
Expand Down
14 changes: 14 additions & 0 deletions 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')
});
140 changes: 140 additions & 0 deletions 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'}
]
}]

]);
131 changes: 131 additions & 0 deletions 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 = <ILanguage>{
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'],
],
},
};
1 change: 1 addition & 0 deletions src/monaco.contribution.ts
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions test/setup.js
Expand Up @@ -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',
Expand Down

0 comments on commit 998a8b2

Please sign in to comment.