Ver código fonte

redis language support added, tests are ok

Can Abacigil 7 anos atrás
pai
commit
5f8c74986c
7 arquivos alterados com 324 adições e 46 exclusões
  1. 2 1
      gulpfile.js
  2. 1 1
      package.json
  3. 7 0
      src/monaco.contribution.ts
  4. 6 32
      src/redis.ts
  5. 2 1
      test/all.js
  6. 11 11
      test/mysql.test.ts
  7. 295 0
      test/redis.test.ts

+ 2 - 1
gulpfile.js

@@ -80,7 +80,8 @@ gulp.task('release', ['clean-release','compile'], function() {
 			bundleOne('src/sb'),
 			bundleOne('src/mysql'),
 			bundleOne('src/redshift'),
-			bundleOne('src/pgsql')
+			bundleOne('src/pgsql'),
+			bundleOne('src/redis')
 		)
 		.pipe(uglify({
 			output: {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@teamsqlio/monaco-languages",
-  "version": "0.9.3",
+  "version": "0.9.4",
   "description": "Bundle of many languages for the Monaco Editor.",
   "scripts": {
     "compile": "node_modules/.bin/gulp compile",

+ 7 - 0
src/monaco.contribution.ts

@@ -293,3 +293,10 @@ registerLanguage({
 	aliases: ['Redshift', 'redshift'],
 	module: './redshift'
 });
+
+registerLanguage({
+	id: 'redis',
+	extensions: ['.redis'],
+	aliases: ['redis'],
+	module: './redis'
+});

+ 6 - 32
src/redis.ts

@@ -9,10 +9,6 @@ import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
 import ILanguage = monaco.languages.IMonarchLanguage;
 
 export const conf: IRichLanguageConfiguration = {
-	comments: {
-		lineComment: '--',
-		blockComment: ['/*', '*/'],
-	},
 	brackets: [
 		['{', '}'],
 		['[', ']'],
@@ -36,7 +32,7 @@ export const conf: IRichLanguageConfiguration = {
 
 export const language = <ILanguage>{
 	defaultToken: '',
-	tokenPostfix: '.sql',
+	tokenPostfix: '.redis',
 	ignoreCase: true,
 
 	brackets: [
@@ -78,12 +74,10 @@ export const language = <ILanguage>{
 	],
 	tokenizer: {
 		root: [
-			{ include: '@comments' },
 			{ include: '@whitespace' },
 			{ include: '@pseudoColumns' },
 			{ include: '@numbers' },
 			{ include: '@strings' },
-			{ include: '@complexIdentifiers' },
 			{ include: '@scopes' },
 			[/[;,.]/, 'delimiter'],
 			[/[()]/, '@brackets'],
@@ -101,19 +95,6 @@ export const language = <ILanguage>{
 		whitespace: [
 			[/\s+/, 'white']
 		],
-		comments: [
-			[/--+.*/, 'comment'],
-			[/#+.*/, 'comment'],
-			[/\/\*/, { token: 'comment.quote', next: '@comment' }]
-		],
-		comment: [
-			[/[^*/]+/, 'comment'],
-			// Not supporting nested comments, as nested comments seem to not be standard?
-			// i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic
-			// [/\/\*/, { token: 'comment.quote', next: '@push' }],    // nested comment not allowed :-(
-			[/\*\//, { token: 'comment.quote', next: '@pop' }],
-			[/./, 'comment']
-		],
 		pseudoColumns: [
 			[/[$][A-Za-z_][\w@#$]*/, {
 				cases: {
@@ -129,24 +110,17 @@ export const language = <ILanguage>{
 		],
 		strings: [
 			[/'/, { token: 'string', next: '@string' }],
-			[/"/, { token: 'string', next: '@string' }]
+			[/"/, { token: 'string.double', next: '@stringDouble' }]
 		],
 		string: [
 			[/[^']+/, 'string'],
-			[/[^"]+/, 'string'],
 			[/''/, 'string'],
-			[/""/, 'string'],
 			[/'/, { token: 'string', next: '@pop' }],
-			[/"/, { token: 'string', next: '@pop' }]
-		],
-		complexIdentifiers: [
-
-			[/`/, { token: 'identifier.quote', next: '@quotedIdentifier' }]
 		],
-		quotedIdentifier: [
-			[/[^`]+/, 'identifier'],
-			[/``/, 'identifier'],
-			[/`/, { token: 'identifier.quote', next: '@pop' }]
+		stringDouble: [
+			[/[^"]+/, 'string.double'],
+			[/""/, 'string.double'],
+			[/"/, { token: 'string.double', next: '@pop' }]
 		],
 		scopes: [
 			// NOT SUPPORTED

+ 2 - 1
test/all.js

@@ -61,7 +61,8 @@ requirejs([
 		'out/test/sb.test',
 		'out/test/mysql.test',
 		'out/test/pgsql.test',
-		'out/test/redshift.test'
+		'out/test/redshift.test',
+		'out/test/redis.test'
 	], function() {
 		run(); // We can launch the tests!
 	});

+ 11 - 11
test/mysql.test.ts

@@ -23,17 +23,17 @@ testTokenization('mysql', [
 		]
 	}],
 
-	// [{
-	// 	line: '-almost a comment',
-	// 	tokens: [
-	// 		{ startIndex: 0, type: 'operator.sql' },
-	// 		{ startIndex: 1, type: 'identifier.sql' },
-	// 		{ startIndex: 7, type: 'white.sql' },
-	// 		{ startIndex: 8, type: 'identifier.sql' },
-	// 		{ startIndex: 9, type: 'white.sql' },
-	// 		{ startIndex: 10, type: 'identifier.sql' }
-	// 	]
-	// }],
+	[{
+		line: '-almost a comment',
+		tokens: [
+			{ startIndex: 0, type: 'operator.sql' },
+			{ startIndex: 1, type: 'identifier.sql' },
+			{ startIndex: 7, type: 'white.sql' },
+			{ startIndex: 8, type: 'identifier.sql' },
+			{ startIndex: 9, type: 'white.sql' },
+			{ startIndex: 10, type: 'keyword.sql' }
+		]
+	}],
 
 	[{
 		line: '/* a full line comment */',

+ 295 - 0
test/redis.test.ts

@@ -0,0 +1,295 @@
+/*---------------------------------------------------------------------------------------------
+ *  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 './testRunner';
+
+testTokenization('redis', [
+
+	// Numbers
+	[{
+		line: '123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '-123',
+		tokens: [
+			{ startIndex: 0, type: 'operator.redis' },
+			{ startIndex: 1, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0xaBc123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0XaBc123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0x',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0x0',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0xAB_CD',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' },
+			{ startIndex: 4, type: 'identifier.redis' }
+		]
+	}],
+
+	[{
+		line: '$',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$-123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$-+-123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$123.5678',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$0.99',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$.99',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$99.',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$0.',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '$.0',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '.',
+		tokens: [
+			{ startIndex: 0, type: 'delimiter.redis' }
+		]
+	}],
+
+	[{
+		line: '123',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '123.5678',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0.99',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '.99',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '99.',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0.',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '.0',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '1E-2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '1E+2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '1E2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '0.1E2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '1.E2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	[{
+		line: '.1E2',
+		tokens: [
+			{ startIndex: 0, type: 'number.redis' }
+		]
+	}],
+
+	// Strings
+
+	[{
+		line: 'SET key1 "Hello"',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.redis' },
+			{ startIndex: 3, type: 'white.redis' },
+			{ startIndex: 4, type: 'identifier.redis' },
+			{ startIndex: 8, type: 'white.redis' },
+			{ startIndex: 9, type: 'string.double.redis' },
+		]
+	}],
+
+	[{
+		line: 'SET key1 \'Hello\'',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.redis' },
+			{ startIndex: 3, type: 'white.redis' },
+			{ startIndex: 4, type: 'identifier.redis' },
+			{ startIndex: 8, type: 'white.redis' },
+			{ startIndex: 9, type: 'string.redis' },
+		]
+	}],
+
+	// Commands
+
+	[{
+		line: 'DEL key1 key2 key3',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.redis' },
+			{ startIndex: 3, type: 'white.redis' },
+			{ startIndex: 4, type: 'identifier.redis' },
+			{ startIndex: 8, type: 'white.redis' },
+			{ startIndex: 9, type: 'identifier.redis' },
+			{ startIndex: 13, type: 'white.redis' },
+			{ startIndex: 14, type: 'identifier.redis' },
+		]
+	}],
+
+	[{
+		line: 'GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.redis' },
+			{ startIndex: 6, type: 'white.redis' },
+			{ startIndex: 7, type: 'identifier.redis' },
+			{ startIndex: 13, type: 'white.redis' },
+			{ startIndex: 14, type: 'number.redis' },
+			{ startIndex: 23, type: 'white.redis' },
+			{ startIndex: 24, type: 'number.redis' },
+			{ startIndex: 33, type: 'white.redis' },
+			{ startIndex: 34, type: 'string.double.redis' },
+			{ startIndex: 43, type: 'white.redis' },
+			{ startIndex: 44, type: 'number.redis' },
+			{ startIndex: 53, type: 'white.redis' },
+			{ startIndex: 54, type: 'number.redis' },
+			{ startIndex: 63, type: 'white.redis' },
+			{ startIndex: 64, type: 'string.double.redis' },
+		]
+	}],
+
+	[{
+		line: 'HGET myhash field1',
+		tokens: [
+			{ startIndex: 0, type: 'keyword.redis' },
+			{ startIndex: 4, type: 'white.redis' },
+			{ startIndex: 5, type: 'identifier.redis' },
+			{ startIndex: 11, type: 'white.redis' },
+			{ startIndex: 12, type: 'identifier.redis' }
+		]
+	}],
+]);