瀏覽代碼

Added cameligo language support

Maksym Bykovskyy 5 年之前
父節點
當前提交
c123d330e7
共有 7 個文件被更改,包括 289 次插入0 次删除
  1. 1 0
      README.md
  2. 1 0
      scripts/bundle.js
  3. 14 0
      src/cameligo/cameligo.contribution.ts
  4. 140 0
      src/cameligo/cameligo.test.ts
  5. 131 0
      src/cameligo/cameligo.ts
  6. 1 0
      src/monaco.contribution.ts
  7. 1 0
      test/setup.js

+ 1 - 0
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

+ 1 - 0
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');

+ 14 - 0
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 - 0
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 - 0
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 - 0
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';

+ 1 - 0
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',