redis language support added, tests are ok

pull/2748/head
Can Abacigil 7 years ago
parent 7382c4690b
commit 5f8c74986c

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

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

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

@ -9,10 +9,6 @@ import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
import ILanguage = monaco.languages.IMonarchLanguage; import ILanguage = monaco.languages.IMonarchLanguage;
export const conf: IRichLanguageConfiguration = { export const conf: IRichLanguageConfiguration = {
comments: {
lineComment: '--',
blockComment: ['/*', '*/'],
},
brackets: [ brackets: [
['{', '}'], ['{', '}'],
['[', ']'], ['[', ']'],
@ -36,7 +32,7 @@ export const conf: IRichLanguageConfiguration = {
export const language = <ILanguage>{ export const language = <ILanguage>{
defaultToken: '', defaultToken: '',
tokenPostfix: '.sql', tokenPostfix: '.redis',
ignoreCase: true, ignoreCase: true,
brackets: [ brackets: [
@ -78,12 +74,10 @@ export const language = <ILanguage>{
], ],
tokenizer: { tokenizer: {
root: [ root: [
{ include: '@comments' },
{ include: '@whitespace' }, { include: '@whitespace' },
{ include: '@pseudoColumns' }, { include: '@pseudoColumns' },
{ include: '@numbers' }, { include: '@numbers' },
{ include: '@strings' }, { include: '@strings' },
{ include: '@complexIdentifiers' },
{ include: '@scopes' }, { include: '@scopes' },
[/[;,.]/, 'delimiter'], [/[;,.]/, 'delimiter'],
[/[()]/, '@brackets'], [/[()]/, '@brackets'],
@ -101,19 +95,6 @@ export const language = <ILanguage>{
whitespace: [ whitespace: [
[/\s+/, 'white'] [/\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: [ pseudoColumns: [
[/[$][A-Za-z_][\w@#$]*/, { [/[$][A-Za-z_][\w@#$]*/, {
cases: { cases: {
@ -129,24 +110,17 @@ export const language = <ILanguage>{
], ],
strings: [ strings: [
[/'/, { token: 'string', next: '@string' }], [/'/, { token: 'string', next: '@string' }],
[/"/, { token: 'string', next: '@string' }] [/"/, { token: 'string.double', next: '@stringDouble' }]
], ],
string: [ string: [
[/[^']+/, 'string'], [/[^']+/, 'string'],
[/[^"]+/, 'string'],
[/''/, 'string'], [/''/, 'string'],
[/""/, 'string'],
[/'/, { token: 'string', next: '@pop' }], [/'/, { token: 'string', next: '@pop' }],
[/"/, { token: 'string', next: '@pop' }]
],
complexIdentifiers: [
[/`/, { token: 'identifier.quote', next: '@quotedIdentifier' }]
], ],
quotedIdentifier: [ stringDouble: [
[/[^`]+/, 'identifier'], [/[^"]+/, 'string.double'],
[/``/, 'identifier'], [/""/, 'string.double'],
[/`/, { token: 'identifier.quote', next: '@pop' }] [/"/, { token: 'string.double', next: '@pop' }]
], ],
scopes: [ scopes: [
// NOT SUPPORTED // NOT SUPPORTED

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

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

@ -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' }
]
}],
]);
Loading…
Cancel
Save