From 65602c1a094a2f1e6023436f73b515d7835c2887 Mon Sep 17 00:00:00 2001 From: DefinitelyNotAGoat Date: Mon, 26 Aug 2019 22:22:22 -0400 Subject: [PATCH] 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/ --- README.md | 1 + scripts/bundle.js | 1 + src/monaco.contribution.ts | 1 + src/pascaligo/pascaligo.contribution.ts | 14 +++ src/pascaligo/pascaligo.test.ts | 139 ++++++++++++++++++++++++ src/pascaligo/pascaligo.ts | 132 ++++++++++++++++++++++ test/setup.js | 1 + 7 files changed, 289 insertions(+) create mode 100644 src/pascaligo/pascaligo.contribution.ts create mode 100644 src/pascaligo/pascaligo.test.ts create mode 100644 src/pascaligo/pascaligo.ts diff --git a/README.md b/README.md index f3000902..68fec4e1 100644 --- a/README.md +++ b/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 diff --git a/scripts/bundle.js b/scripts/bundle.js index 251a2439..ebef7632 100644 --- a/scripts/bundle.js +++ b/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'); diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index bd1b5303..2a65b431 100644 --- a/src/monaco.contribution.ts +++ b/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'; diff --git a/src/pascaligo/pascaligo.contribution.ts b/src/pascaligo/pascaligo.contribution.ts new file mode 100644 index 00000000..e9a80a55 --- /dev/null +++ b/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') +}); diff --git a/src/pascaligo/pascaligo.test.ts b/src/pascaligo/pascaligo.test.ts new file mode 100644 index 00000000..905d59d9 --- /dev/null +++ b/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'} + ] + }] + +]); diff --git a/src/pascaligo/pascaligo.ts b/src/pascaligo/pascaligo.ts new file mode 100644 index 00000000..232a7e4c --- /dev/null +++ b/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 = { + 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'], + ], + }, +}; diff --git a/test/setup.js b/test/setup.js index e72fb2c1..13363986 100644 --- a/test/setup.js +++ b/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',