alan.invents 6 лет назад
Родитель
Сommit
9d51b7ced9
6 измененных файлов с 281 добавлено и 4 удалено
  1. 4 3
      scripts/bundle.js
  2. 1 0
      src/monaco.contribution.ts
  3. 16 0
      src/tcl/tcl.contribution.ts
  4. 100 0
      src/tcl/tcl.test.ts
  5. 159 0
      src/tcl/tcl.ts
  6. 1 1
      test/setup.js

+ 4 - 3
scripts/bundle.js

@@ -66,10 +66,11 @@ bundleOne('csp/csp');
 bundleOne('scheme/scheme');
 bundleOne('clojure/clojure');
 bundleOne('shell/shell');
-bundleOne('perl/perl'),
-bundleOne('powerquery/powerquery')
-bundleOne('azcli/azcli')
+bundleOne('perl/perl');
+bundleOne('powerquery/powerquery');
+bundleOne('azcli/azcli');
 bundleOne('apex/apex');
+bundleOne('tcl/tcl');
 
 function bundleOne(moduleId, exclude) {
 	requirejs.optimize({

+ 1 - 0
src/monaco.contribution.ts

@@ -43,6 +43,7 @@ import './solidity/solidity.contribution';
 import './sql/sql.contribution';
 import './st/st.contribution';
 import './swift/swift.contribution';
+import './tcl/tcl.contribution';
 import './typescript/typescript.contribution';
 import './vb/vb.contribution';
 import './xml/xml.contribution';

+ 16 - 0
src/tcl/tcl.contribution.ts

@@ -0,0 +1,16 @@
+/*---------------------------------------------------------------------------------------------
+ *  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';
+
+const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
+
+registerLanguage({
+	id: 'tcl',
+	extensions: ['.tcl'],
+	aliases: ['tcl', 'Tcl', 'tcltk', 'TclTk', 'tcl/tk', 'Tcl/Tk'],
+	loader: () => _monaco.Promise.wrap(import('./tcl'))
+});

+ 100 - 0
src/tcl/tcl.test.ts

@@ -0,0 +1,100 @@
+/*---------------------------------------------------------------------------------------------
+ *  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('tcl', [
+	// Definitions
+	[{
+		line: 'set var 1',
+		tokens: [
+			{startIndex: 0, type: 'keyword.flow.tcl'}, // `set`
+			{startIndex: 3, type: 'source.tcl'},       // ` `
+			{startIndex: 4, type: 'type.tcl'},         // `var`
+			{startIndex: 7, type: 'white.tcl'},        // ` `
+			{startIndex: 8, type: 'number.tcl'}        // `1`
+		]
+	}],
+	
+	[{
+		line: 'proc func {a b} {}',
+		tokens: [
+			{startIndex: 0, type: 'keyword.flow.tcl'},     // `proc`
+			{startIndex: 4, type: 'source.tcl'},           // ` `
+			{startIndex: 5, type: 'type.tcl'},             // `func`
+			{startIndex: 9, type: 'white.tcl'},           // ` `
+			{startIndex: 10, type: 'delimiter.curly.tcl'}, // `{`
+			{startIndex: 11, type: 'operator.scss.tcl'},   // `a`
+			{startIndex: 12, type: 'white.tcl'},          // ` `
+			{startIndex: 13, type: 'operator.scss.tcl'},   // `b`
+			{startIndex: 14, type: 'delimiter.curly.tcl'}, // `}`
+			{startIndex: 15, type: 'white.tcl'},          // ` `
+			{startIndex: 16, type: 'delimiter.curly.tcl'}  // `{}`
+		]
+	}],
+	
+	// Keywords
+	[{
+		line: 'if 1 return',
+		tokens: [
+			{startIndex: 0, type: 'keyword.tcl'},
+			{startIndex: 2, type: 'white.tcl'},
+			{startIndex: 3, type: 'number.tcl'},
+			{startIndex: 4, type: 'white.tcl'},
+			{startIndex: 5, type: 'keyword.tcl'}
+		]
+	}],
+	
+	
+	// Variables
+	[{
+		line: '$var1 $::var2 $$var3 ${var 4} $::{var 5}',
+		tokens: [
+			{startIndex: 0, type: 'type.identifier.tcl'},
+			{startIndex: 5, type: 'white.tcl'},
+			{startIndex: 6, type: 'type.identifier.tcl'},
+			{startIndex: 13, type: 'white.tcl'},
+			{startIndex: 14, type: 'type.identifier.tcl'},
+			{startIndex: 20, type: 'white.tcl'},
+			{startIndex: 21, type: 'identifier.tcl'},
+			{startIndex: 23, type: 'type.identifier.tcl'},
+			{startIndex: 28, type: 'identifier.tcl'},
+			{startIndex: 29, type: 'white.tcl'},
+			{startIndex: 30, type: 'identifier.tcl'},
+			{startIndex: 34, type: 'type.identifier.tcl'},
+			{startIndex: 39, type: 'identifier.tcl'}
+		]
+	}],
+	
+	// Function and variable string interpolation
+	[{
+		line: 'puts "$var1 + ${var 2} = [expr $var1 + ${var 2}]"',
+		tokens: [
+			{startIndex: 0, type: 'variable.tcl'},
+			{startIndex: 4, type: 'white.tcl'},
+			{startIndex: 5, type: 'string.quote.tcl'},
+			{startIndex: 6, type: 'type.identifier.tcl'},
+			{startIndex: 11, type: 'string.tcl'},
+			{startIndex: 14, type: 'identifier.tcl'},
+			{startIndex: 16, type: 'type.identifier.tcl'},
+			{startIndex: 21, type: 'identifier.tcl'},
+			{startIndex: 22, type: 'string.tcl'},
+			{startIndex: 25, type: 'delimiter.square.tcl'},
+			{startIndex: 26, type: 'keyword.tcl'},
+			{startIndex: 30, type: 'white.tcl'},
+			{startIndex: 31, type: 'type.identifier.tcl'},
+			{startIndex: 36, type: 'white.tcl'},
+			{startIndex: 37, type: 'operator.tcl'},
+			{startIndex: 38, type: 'white.tcl'},
+			{startIndex: 39, type: 'identifier.tcl'},
+			{startIndex: 41, type: 'type.identifier.tcl'},
+			{startIndex: 46, type: 'identifier.tcl'},
+			{startIndex: 47, type: 'delimiter.square.tcl'},
+			{startIndex: 48, type: 'string.quote.tcl'}
+		]
+	}]
+]);

+ 159 - 0
src/tcl/tcl.ts

@@ -0,0 +1,159 @@
+/*---------------------------------------------------------------------------------------------
+ *  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 = {
+	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>{
+	tokenPostfix: '.tcl',
+	
+	specialFunctions: [
+		'set', 'unset', 'rename', 'variable', 'proc', 'coroutine',
+		'foreach',
+		'incr', 'append',
+		'lappend', 'linsert', 'lreplace'
+	],
+
+	mainFunctions: [
+		'if', 'then', 'elseif', 'else', 'case', 'switch', 'while', 'for',
+		'break', 'continue', 'return',
+		'package', 'namespace',
+		'catch', 'exit',
+		'eval', 'expr', 'uplevel', 'upvar'
+	],
+
+	builtinFunctions: [
+		'file', 'info', 'concat', 'join', 'lindex',
+		'list', 'llength', 'lrange', 'lsearch', 'lsort', 'split',
+		'array', 'parray', 'binary', 'format', 'regexp', 'regsub', 'scan', 'string',
+		'subst', 'dict', 'cd', 'clock', 'exec', 'glob', 'pid', 'pwd', 'close', 'eof', 'fblocked',
+		'fconfigure', 'fcopy', 'fileevent', 'flush', 'gets', 'open', 'puts', 'read', 'seek',
+		'socket', 'tell', 'interp', 'after', 'auto_execok',
+		'auto_load', 'auto_mkindex', 'auto_reset', 'bgerror', 'error',
+		'global', 'history', 'load', 'source', 'time', 'trace',
+		'unknown', 'unset', 'update', 'vwait', 'winfo', 'wm', 'bind', 'event',
+		'pack', 'place', 'grid', 'font', 'bell', 'clipboard', 'destroy', 'focus', 'grab', 'lower',
+		'option', 'raise', 'selection', 'send', 'tk', 'tkwait', 'tk_bisque', 'tk_focusNext',
+		'tk_focusPrev', 'tk_focusFollowsMouse', 'tk_popup', 'tk_setPalette'
+	],
+
+	symbols: /[=><!~?:&|+\-*\/\^%]+/,
+	
+	brackets: [
+		{open: '(', close: ')', token: 'delimiter.parenthesis'},
+		{open: '{', close: '}', token: 'delimiter.curly'},
+		{open: '[', close: ']', token: 'delimiter.square'}
+	],
+	
+	escapes: /\\(?:[abfnrtv\\"'\[\]\{\};\$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
+
+	variables: /(?:\$+(?:(?:\:\:?)?[a-zA-Z_]\w*)+)/,
+
+	tokenizer: {
+		root: [
+			// identifiers and keywords
+
+			[/[a-zA-Z_]\w*/, {cases: {
+				'@specialFunctions': {token: 'keyword.flow', next: '@specialFunc'},
+				'@mainFunctions': 'keyword',
+				'@builtinFunctions': 'variable',
+				'@default': 'operator.scss'
+			}}],
+
+			[/\s+\-+(?!\d|\.)\w*|{\*}/, 'metatag'],
+
+			// whitespace
+			{include: '@whitespace'},
+
+			// delimiters and operators
+			[/[{}()\[\]]/, '@brackets'],
+			[/@symbols/, 'operator'],
+			[/\$+(?:\:\:)?\{/, {token: 'identifier', next: '@nestedVariable'}],
+			[/@variables/, 'type.identifier'],
+			[/\.(?!\d|\.)[\w\-]*/, 'operator.sql'],
+
+			// numbers
+			[/\d+(\.\d+)?/, 'number'],
+			[/\d+/, 'number'],
+
+			// delimiter
+			[/;/, 'delimiter'],
+
+			// strings
+			[/"/,  {token: 'string.quote', bracket: '@open', next: '@dstring'}],
+			[/'/,  {token: 'string.quote', bracket: '@open', next: '@sstring'}]
+		],
+
+		dstring: [
+			[/\[/, {token: '@brackets', next: '@nestedCall'}],
+			[/\$+(?:\:\:)?\{/, {token: 'identifier', next: '@nestedVariable'}],
+			[/@variables/, 'type.identifier'],
+			[/[^\\$\[\]"]+/, 'string'],
+			[/@escapes/, 'string.escape'],
+			[/"/,					{token: 'string.quote', bracket: '@close', next: '@pop'}],
+		],
+
+		sstring: [
+			[/\[/, {token: '@brackets', next: '@nestedCall'}],
+			[/\$+(?:\:\:)?\{/, {token: 'identifier', next: '@nestedVariable'}],
+			[/@variables/, 'type.identifier'],
+			[/[^\\$\[\]']+/,  'string'],
+			[/@escapes/, 'string.escape'],
+			[/'/,					{token: 'string.quote', bracket: '@close', next: '@pop'}]
+		],
+
+		whitespace: [
+			[/[ \t\r\n]+/, 'white'],
+			[/#.*\\$/, 			{token: 'comment', next: '@newlineComment'}],
+			[/#.*(?!\\)$/, 'comment']
+		],
+
+		newlineComment: [
+			[/.*\\$/, 'comment'],
+			[/.*(?!\\)$/, {token: 'comment', next: '@pop'}]
+		],
+
+		nestedVariable: [
+			[/[^\{\}\$]+/, 'type.identifier'],
+			[/\}/, {token: 'identifier', next: '@pop'}]
+		],
+
+		nestedCall: [
+			[/\[/, {token: '@brackets', next: '@nestedCall'}],
+			[/\]/, {token: '@brackets', next: '@pop'}],
+			{include: 'root'}
+		],
+
+		specialFunc: [
+			[/"/, {token: 'string', next: '@dstring'}],
+			[/'/, {token: 'string', next: '@sstring'}],
+			[/(?:(?:\:\:?)?[a-zA-Z_]\w*)+/, {token: 'type', next: '@pop'}],
+		]
+	}
+};

+ 1 - 1
test/setup.js

@@ -1,4 +1,3 @@
-
 define('vs/css', [], {
 	load: function (name, req, load) {
 		load({});
@@ -70,6 +69,7 @@ define(['require'], function () {
 			'release/dev/sql/sql.test',
 			'release/dev/st/st.test',
 			'release/dev/swift/swift.test',
+			'release/dev/tcl/tcl.test',
 			'release/dev/typescript/typescript.test',
 			'release/dev/vb/vb.test',
 			'release/dev/xml/xml.test',