浏览代码

pascaligo: adding pascaligo language support

Pascaligo is a layer 2 smart contract language for the Tezos blockchain.
For more info please see: https://ligolang.org/
DefinitelyNotAGoat 5 年之前
父节点
当前提交
65602c1a09
共有 7 个文件被更改,包括 289 次插入0 次删除
  1. 1 0
      README.md
  2. 1 0
      scripts/bundle.js
  3. 1 0
      src/monaco.contribution.ts
  4. 14 0
      src/pascaligo/pascaligo.contribution.ts
  5. 139 0
      src/pascaligo/pascaligo.test.ts
  6. 132 0
      src/pascaligo/pascaligo.ts
  7. 1 0
      test/setup.js

+ 1 - 0
README.md

@@ -27,6 +27,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed
 * mysql
 * objective-c
 * pascal
+* pascaligo
 * pgsql
 * php
 * postiats

+ 1 - 0
scripts/bundle.js

@@ -42,6 +42,7 @@ bundleOne('markdown/markdown');
 bundleOne('msdax/msdax');
 bundleOne('objective-c/objective-c');
 bundleOne('pascal/pascal');
+bundleOne('pascaligo/pascaligo');
 bundleOne('php/php');
 bundleOne('powershell/powershell');
 bundleOne('postiats/postiats');

+ 1 - 0
src/monaco.contribution.ts

@@ -27,6 +27,7 @@ import './msdax/msdax.contribution';
 import './mysql/mysql.contribution';
 import './objective-c/objective-c.contribution';
 import './pascal/pascal.contribution';
+import './pascaligo/pascaligo.contribution';
 import './pgsql/pgsql.contribution';
 import './php/php.contribution';
 import './postiats/postiats.contribution';

+ 14 - 0
src/pascaligo/pascaligo.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: 'pascaligo',
+	extensions: ['.ligo'],
+	aliases: ['Pascaligo', 'ligo'],
+	loader: () => import('./pascaligo')
+});

+ 139 - 0
src/pascaligo/pascaligo.test.ts

@@ -0,0 +1,139 @@
+/*---------------------------------------------------------------------------------------------
+ *  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('pascaligo', [
+
+	// Comments - single line
+	[{
+		line: '//',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '    // a comment',
+		tokens: [
+			{ startIndex: 0, type: 'white.pascaligo' },
+			{ startIndex: 4, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '// a comment',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '//sticky comment',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	// Comments - multi line (single line)
+	[{
+		line: '(**)',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '    (* a comment *)',
+		tokens: [
+			{ startIndex: 0, type: 'white.pascaligo' },
+			{ startIndex: 4, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '(* a comment *)',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	[{
+		line: '(*sticky comment*)',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}],
+
+	// Comments - multi line (multi line)
+	[{
+		line: '(* start of multiline comment ',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo' }
+		]
+	}, {
+		line: 'a comment between curly',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo'}
+		]
+	}, {
+		line: 'end of multiline comment*)',
+		tokens: [
+			{ startIndex: 0, type: 'comment.pascaligo'}
+		]
+	}],
+
+	// Keywords
+	[{
+		line: 'function add (const a',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.function.pascaligo'},
+			{ startIndex: 8, type: 'white.pascaligo'},
+			{ startIndex: 9, type: 'identifier.pascaligo'},
+			{ startIndex: 12, type: 'white.pascaligo'},
+			{ startIndex: 13, type: 'delimiter.parenthesis.pascaligo'},
+			{ startIndex: 14, type: 'keyword.const.pascaligo'},
+			{ startIndex: 19, type: 'white.pascaligo'},
+			{ startIndex: 20, type: 'identifier.pascaligo'},
+		]
+	}],
+
+	// Numbers
+	[{
+		line: '0',
+		tokens: [
+			{ startIndex: 0, type: 'number.pascaligo'}
+		]
+	}],
+	[{
+		line: '0;',
+		tokens: [
+			{ startIndex: 0, type: 'number.pascaligo'},
+			{ startIndex: 1, type: 'delimiter.pascaligo'}
+		]
+	}],
+	[{
+		line: '2.4',
+		tokens: [
+			{ startIndex: 0, type: 'number.float.pascaligo'}
+		]
+	}],
+	[{
+		line: '2.4;',
+		tokens: [
+			{ startIndex: 0, type: 'number.float.pascaligo'},
+			{ startIndex: 3, type: 'delimiter.pascaligo'}
+		]
+	}],
+	[{
+		line: '$123FF',
+		tokens: [
+			{ startIndex: 0, type: 'number.hex.pascaligo'}
+		]
+	}]
+
+]);

+ 132 - 0
src/pascaligo/pascaligo.ts

@@ -0,0 +1,132 @@
+/*---------------------------------------------------------------------------------------------
+ *  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: '.pascaligo',
+	ignoreCase: true,
+
+	brackets: [
+		{ open: '{', close: '}', token: 'delimiter.curly' },
+		{ open: '[', close: ']', token: 'delimiter.square' },
+		{ open: '(', close: ')', token: 'delimiter.parenthesis' },
+		{ open: '<', close: '>', token: 'delimiter.angle' }
+	],
+
+	keywords: [
+        'begin', 'block', 'case', 'const', 'else', 'end',
+        'fail', 'for', 'from', 'function', 'if', 'is', 'nil',
+        'of', 'remove', 'return', 'skip', 'then', 'type', 'var',
+        'while', 'with', 'option', 'None', 'transaction'
+	],
+
+	typeKeywords: [
+		'bool', 'int', 'list', 'map', 'nat', 'record',
+		'string', 'unit', 'address', 'map', 'mtz', 'xtz'
+	],
+
+	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
test/setup.js

@@ -51,6 +51,7 @@ define(['require'], function () {
 			'release/dev/mysql/mysql.test',
 			'release/dev/objective-c/objective-c.test',
 			'release/dev/pascal/pascal.test',
+			'release/dev/pascaligo/pascaligo.test',
 			'release/dev/perl/perl.test',
 			'release/dev/pgsql/pgsql.test',
 			'release/dev/php/php.test',