From 5f8c74986c05c4ea1c93d9c2dd888d3877580b14 Mon Sep 17 00:00:00 2001 From: Can Abacigil Date: Tue, 3 Oct 2017 12:25:54 +0300 Subject: [PATCH] redis language support added, tests are ok --- gulpfile.js | 3 +- package.json | 2 +- src/monaco.contribution.ts | 7 + src/redis.ts | 38 +---- test/all.js | 3 +- test/mysql.test.ts | 22 +-- test/redis.test.ts | 295 +++++++++++++++++++++++++++++++++++++ 7 files changed, 324 insertions(+), 46 deletions(-) create mode 100644 test/redis.test.ts diff --git a/gulpfile.js b/gulpfile.js index 62ce2045..eb068c65 100644 --- a/gulpfile.js +++ b/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: { diff --git a/package.json b/package.json index 07de5384..bd1eb346 100644 --- a/package.json +++ b/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", diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 70a37a23..858c48ac 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -293,3 +293,10 @@ registerLanguage({ aliases: ['Redshift', 'redshift'], module: './redshift' }); + +registerLanguage({ + id: 'redis', + extensions: ['.redis'], + aliases: ['redis'], + module: './redis' +}); diff --git a/src/redis.ts b/src/redis.ts index a722dc45..be33b8c8 100644 --- a/src/redis.ts +++ b/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 = { defaultToken: '', - tokenPostfix: '.sql', + tokenPostfix: '.redis', ignoreCase: true, brackets: [ @@ -78,12 +74,10 @@ export const language = { ], 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 = { 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 = { ], 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 diff --git a/test/all.js b/test/all.js index e53c5926..28d7f2c1 100644 --- a/test/all.js +++ b/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! }); diff --git a/test/mysql.test.ts b/test/mysql.test.ts index 0faf6c30..18ec3b9d 100644 --- a/test/mysql.test.ts +++ b/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 */', diff --git a/test/redis.test.ts b/test/redis.test.ts new file mode 100644 index 00000000..83a96b83 --- /dev/null +++ b/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' } + ] + }], +]);