Browse Source

Added azcli

Viktar Pakanechny 7 năm trước cách đây
mục cha
commit
e0ecde0617
7 tập tin đã thay đổi với 245 bổ sung2 xóa
  1. 1 0
      README.md
  2. 2 1
      scripts/bundle.js
  3. 17 0
      src/azcli/azcli.contribution.ts
  4. 157 0
      src/azcli/azcli.test.ts
  5. 65 0
      src/azcli/azcli.ts
  6. 1 0
      src/monaco.contribution.ts
  7. 2 1
      test/setup.js

+ 1 - 0
README.md

@@ -4,6 +4,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed
 
 ![monaco-languages](https://cloud.githubusercontent.com/assets/5047891/15938606/1fd4bac6-2e74-11e6-8839-d455da8bc8a7.gif)
 
+* azcli
 * bat
 * clojure
 * coffee script

+ 2 - 1
scripts/bundle.js

@@ -64,7 +64,8 @@ bundleOne('csp/csp');
 bundleOne('scheme/scheme');
 bundleOne('clojure/clojure');
 bundleOne('shell/shell');
-bundleOne('perl/perl')
+bundleOne('perl/perl'),
+bundleOne('azcli/azcli')
 
 function bundleOne(moduleId, exclude) {
 	requirejs.optimize({

+ 17 - 0
src/azcli/azcli.contribution.ts

@@ -0,0 +1,17 @@
+/*---------------------------------------------------------------------------------------------
+ *  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';
+
+// Allow for running under nodejs/requirejs in tests
+const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
+
+registerLanguage({
+	id: 'azcli',
+	extensions: ['.azcli'],
+	aliases: ['Azure CLI', 'azcli'],
+	loader: () => _monaco.Promise.wrap(import('./azcli'))
+});

+ 157 - 0
src/azcli/azcli.test.ts

@@ -0,0 +1,157 @@
+/*---------------------------------------------------------------------------------------------
+ *  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 as actualTestTokenization, ITestItem } from '../test/testRunner';
+
+function testTokenization(_language: string | string[], tests: ITestItem[][]): void {
+	tests = tests.map(t => {
+		return t.map(t => {
+			return {
+				line: t.line.replace(/\n/g, ' '),
+				tokens: t.tokens
+			};
+		});
+	});
+	actualTestTokenization(_language, tests);
+}
+
+testTokenization('azcli', [
+	// Comment single line
+	[{
+		line: '#',
+		tokens: [
+			{ startIndex: 0, type: 'comment.azcli' }
+		]
+	}],
+	[{
+		line: '# az find -q secret',
+		tokens: [
+			{ startIndex: 0, type: 'comment.azcli' }
+		]
+	}],
+	[{
+		line: '    # az find -q secret',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' },
+			{ startIndex: 4, type: 'comment.azcli' }
+		]
+	}],
+	[{
+		line: '#az find -q secret',
+		tokens: [
+			{ startIndex: 0, type: 'comment.azcli' }
+		]
+	}],
+
+	// Other cases
+	[{
+		line: 'az find -q secret',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' },
+			{ startIndex: 7, type: 'key.identifier.azcli' },
+			{ startIndex: 11, type: 'string.azcli' }
+		]
+	}],
+	[{
+		line: '',
+		tokens: [
+		]
+	}],
+	[{
+		line: ' ',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}],
+	[{
+		line: '--assignee',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' }
+		]
+	}],
+	[{
+		line: '    --service-principal',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' },
+			{ startIndex: 3, type: 'key.identifier.azcli' }
+		]
+	}],
+	[{
+		line: 'az ad sp create-for-rb  --name ServicePrincipalName --password PASSWORD',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' },
+			{ startIndex: 23, type: 'key.identifier.azcli' },
+			{ startIndex: 31, type: 'string.azcli' },
+			{ startIndex: 52, type: 'key.identifier.azcli' },
+			{ startIndex: 63, type: 'string.azcli' }
+		]
+	}],
+	[{
+		line: '--name!~`\"$%^&*(|\/\.,-=+',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' }
+		]
+	}],
+	[{
+		line: '--name#some comment',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' },
+			{ startIndex: 6, type: 'comment.azcli' }
+		]
+	}],
+	[{
+		line: '--query osPro ``````',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' },
+			{ startIndex: 8, type: 'string.azcli' }
+		]
+	}],
+	[{
+		line: 'az ad sp create-for-rbac',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}],
+	[{
+		line: '123456789',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}],
+	[{
+		line: '- abc',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' },
+			{ startIndex: 2, type: 'string.azcli' }
+		]
+	}],
+	[{
+		line: '- @!$()',
+		tokens: [
+			{ startIndex: 0, type: 'key.identifier.azcli' },
+			{ startIndex: 2, type: 'string.azcli' }
+		]
+	}],
+	[{
+		line: '""',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}],
+	[{
+		line: '// some text',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}],
+	[{
+		line: `'APP_ID'`,
+		tokens: [
+			{ startIndex: 0, type: 'keyword.azcli' }
+		]
+	}]
+]);

+ 65 - 0
src/azcli/azcli.ts

@@ -0,0 +1,65 @@
+/*---------------------------------------------------------------------------------------------
+ *  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: '#',
+	}
+};
+
+export const language = <ILanguage>{
+	defaultToken: 'keyword',
+	ignoreCase: true,
+	tokenPostfix: '.azcli',
+
+	str: /[^#\s]/,
+
+	tokenizer: {
+		root: [
+			{include: '@comment'},
+			[/\s-+@str*\s*/, {
+				cases: {
+				  '@eos': { token: 'key.identifier', next: '@popall' },
+				  '@default': { token: 'key.identifier', next: '@type' }
+				}
+			}],
+			[/^-+@str*\s*/, {
+				cases: {
+				  '@eos': { token: 'key.identifier', next: '@popall' },
+				  '@default': { token: 'key.identifier', next: '@type' }
+				}
+			}]
+		],
+
+		type: [
+			{include: '@comment'},
+			[/-+@str*\s*/, {
+				cases: {
+					'@eos': { token: 'key.identifier', next: '@popall' },
+					'@default': 'key.identifier'
+				}
+			}],
+			[/@str+\s*/, {
+				cases: {
+					'@eos': { token: 'string', next: '@popall' },
+					'@default': 'string'
+			  	}
+			}]
+		],
+
+		comment: [
+			[/#.*$/, {
+				cases: {
+					'@eos': { token: 'comment', next: '@popall' }
+				}
+			}]
+		]
+	}
+};

+ 1 - 0
src/monaco.contribution.ts

@@ -48,3 +48,4 @@ import './scheme/scheme.contribution';
 import './clojure/clojure.contribution';
 import './shell/shell.contribution';
 import './perl/perl.contribution';
+import './azcli/azcli.contribution';

+ 2 - 1
test/setup.js

@@ -68,7 +68,8 @@ define(['require'], function (require) {
 			'release/dev/scheme/scheme.test',
 			'release/dev/clojure/clojure.test',
 			'release/dev/shell/shell.test',
-			'release/dev/perl/perl.test'
+			'release/dev/perl/perl.test',
+			'release/dev/azcli/azcli.test'
 		], function () {
 			run(); // We can launch the tests!
 		}, function (err) {