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

pascaligo: adding pascaligo language support #69

Merged
merged 1 commit into from Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed
* mysql
* objective-c
* pascal
* pascaligo
* pgsql
* php
* postiats
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.js
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/monaco.contribution.ts
Expand Up @@ -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';
Expand Down
14 changes: 14 additions & 0 deletions 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 changes: 139 additions & 0 deletions 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 changes: 132 additions & 0 deletions 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 change: 1 addition & 0 deletions test/setup.js
Expand Up @@ -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',
Expand Down