Remove language registration, configuration and tokenization
parent
44cb53cd6e
commit
95c8a531a2
@ -1,44 +0,0 @@
|
|||||||
declare module "assert" {
|
|
||||||
function internal (value: any, message?: string): void;
|
|
||||||
namespace internal {
|
|
||||||
export class AssertionError implements Error {
|
|
||||||
name: string;
|
|
||||||
message: string;
|
|
||||||
actual: any;
|
|
||||||
expected: any;
|
|
||||||
operator: string;
|
|
||||||
generatedMessage: boolean;
|
|
||||||
|
|
||||||
constructor(options?: {message?: string; actual?: any; expected?: any;
|
|
||||||
operator?: string; stackStartFunction?: Function});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fail(actual?: any, expected?: any, message?: string, operator?: string): void;
|
|
||||||
export function ok(value: any, message?: string): void;
|
|
||||||
export function equal(actual: any, expected: any, message?: string): void;
|
|
||||||
export function notEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export function deepEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export function notDeepEqual(acutal: any, expected: any, message?: string): void;
|
|
||||||
export function strictEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export function notStrictEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export function deepStrictEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export function notDeepStrictEqual(actual: any, expected: any, message?: string): void;
|
|
||||||
export var throws: {
|
|
||||||
(block: Function, message?: string): void;
|
|
||||||
(block: Function, error: Function, message?: string): void;
|
|
||||||
(block: Function, error: RegExp, message?: string): void;
|
|
||||||
(block: Function, error: (err: any) => boolean, message?: string): void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export var doesNotThrow: {
|
|
||||||
(block: Function, message?: string): void;
|
|
||||||
(block: Function, error: Function, message?: string): void;
|
|
||||||
(block: Function, error: RegExp, message?: string): void;
|
|
||||||
(block: Function, error: (err: any) => boolean, message?: string): void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function ifError(value: any): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export = internal;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
||||||
*--------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
declare function run(): void;
|
|
||||||
|
|
||||||
declare function suite(name: string, fn: (err?)=>void);
|
|
||||||
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
|
|
||||||
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
|
|
||||||
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
|
|
||||||
declare function setup(fn: (done?: (err?)=>void)=>void);
|
|
||||||
declare function teardown(fn: (done?: (err?)=>void)=>void);
|
|
@ -1,502 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* 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 * as assert from 'assert';
|
|
||||||
import {createTokenizationSupport, Language} from '../tokenization';
|
|
||||||
|
|
||||||
suite('tokenization', () => {
|
|
||||||
|
|
||||||
interface ITestItem {
|
|
||||||
line: string;
|
|
||||||
tokens: monaco.languages.IToken[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function executeTokenizationTests(tests:ITestItem[][]): void {
|
|
||||||
let tokenizationSupport = createTokenizationSupport(Language.EcmaScript5);
|
|
||||||
for (let i = 0, len = tests.length; i < len; i++) {
|
|
||||||
assert.ok(true, 'TEST #' + i);
|
|
||||||
executeTokenizationTest(tokenizationSupport, tests[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function executeTokenizationTest(tokenizationSupport: monaco.languages.TokensProvider, tests:ITestItem[]): void {
|
|
||||||
let state = tokenizationSupport.getInitialState();
|
|
||||||
for (let i = 0, len = tests.length; i < len; i++) {
|
|
||||||
assert.ok(true, tests[i].line);
|
|
||||||
|
|
||||||
let result = tokenizationSupport.tokenize(tests[i].line, state);
|
|
||||||
|
|
||||||
if (tests[i].tokens) {
|
|
||||||
assert.deepEqual(result.tokens, tests[i].tokens, 'Tokenizing line ' + tests[i].line + ': ' + JSON.stringify(tests[i].tokens, null, '\t'));
|
|
||||||
}
|
|
||||||
|
|
||||||
state = result.endState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('', () => {
|
|
||||||
executeTokenizationTests([
|
|
||||||
|
|
||||||
// Keywords
|
|
||||||
[{
|
|
||||||
line: 'var x = function() { };',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 16, scopes: 'delimiter.parenthesis.js' },
|
|
||||||
{ startIndex: 18, scopes: '' },
|
|
||||||
{ startIndex: 19, scopes: 'delimiter.bracket.js' },
|
|
||||||
{ startIndex: 20, scopes: '' },
|
|
||||||
{ startIndex: 21, scopes: 'delimiter.bracket.js' },
|
|
||||||
{ startIndex: 22, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: ' var ',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 7, scopes: '' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Comments - single line
|
|
||||||
[{
|
|
||||||
line: '//',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: ' // a comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '// a comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '// a comment /*',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '// a comment /**',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '//sticky comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'var x = 1; // my comment // is a nice one',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'number.js' },
|
|
||||||
{ startIndex: 9, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 10, scopes: '' },
|
|
||||||
{ startIndex: 11, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Comments - range comment, single line
|
|
||||||
[{
|
|
||||||
line: '/* a simple comment */',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'var x = /* a simple comment */ 1;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'comment.js' },
|
|
||||||
{ startIndex: 30, scopes: '' },
|
|
||||||
{ startIndex: 31, scopes: 'number.js' },
|
|
||||||
{ startIndex: 32, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'x = /**/;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'comment.js' },
|
|
||||||
{ startIndex: 8, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'x = /*/;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Comments - range comment, multi lines
|
|
||||||
[{
|
|
||||||
line: '/* a multiline comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}, {
|
|
||||||
line: 'can actually span',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}, {
|
|
||||||
line: 'multiple lines */',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'var x = /* start a comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'comment.js' }
|
|
||||||
]}, {
|
|
||||||
line: ' a ',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}, {
|
|
||||||
line: 'and end it */ var a = 2;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' },
|
|
||||||
{ startIndex: 13, scopes: '' },
|
|
||||||
{ startIndex: 14, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 17, scopes: '' },
|
|
||||||
{ startIndex: 18, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 19, scopes: '' },
|
|
||||||
{ startIndex: 20, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 21, scopes: '' },
|
|
||||||
{ startIndex: 22, scopes: 'number.js' },
|
|
||||||
{ startIndex: 23, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Strings
|
|
||||||
[{
|
|
||||||
line: 'var a = \'a\';',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'keyword.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'string.js' },
|
|
||||||
{ startIndex: 11, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '"use strict";',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'string.js' },
|
|
||||||
{ startIndex: 12, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'b = a + " \'cool\' "',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'string.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '"escaping \\"quotes\\" is cool"',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'string.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '\'\'\'',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'string.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '\'\\\'\'',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'string.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '\'be careful \\not to escape\'',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'string.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Numbers
|
|
||||||
[{
|
|
||||||
line: '0',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: ' 0',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: '' },
|
|
||||||
{ startIndex: 1, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: ' 0 ',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: '' },
|
|
||||||
{ startIndex: 1, scopes: 'number.js' },
|
|
||||||
{ startIndex: 2, scopes: '' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0 ',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: '' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0+0',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 2, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '100+10',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 3, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0 + 0',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0123',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '01239',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0x',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: 'identifier.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '0x123',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Regular Expressions
|
|
||||||
[{
|
|
||||||
line: '//',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '/**/',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '/***/',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'comment.doc.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '5 / 3;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' },
|
|
||||||
{ startIndex: 5, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
// Advanced regular expressions
|
|
||||||
[{
|
|
||||||
line: '1 / 2; /* comment',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' },
|
|
||||||
{ startIndex: 5, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 6, scopes: '' },
|
|
||||||
{ startIndex: 7, scopes: 'comment.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '1 / 2 / x / b;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' },
|
|
||||||
{ startIndex: 5, scopes: '' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 9, scopes: '' },
|
|
||||||
{ startIndex: 10, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 11, scopes: '' },
|
|
||||||
{ startIndex: 12, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 13, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'a /ads/ b;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 7, scopes: '' },
|
|
||||||
{ startIndex: 8, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 9, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '1/(2/3)/2/3;',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'number.js' },
|
|
||||||
{ startIndex: 1, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.parenthesis.js' },
|
|
||||||
{ startIndex: 3, scopes: 'number.js' },
|
|
||||||
{ startIndex: 4, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 5, scopes: 'number.js' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.parenthesis.js' },
|
|
||||||
{ startIndex: 7, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 8, scopes: 'number.js' },
|
|
||||||
{ startIndex: 9, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 10, scopes: 'number.js' },
|
|
||||||
{ startIndex: 11, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '{ key: 123 }',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'delimiter.bracket.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 6, scopes: '' },
|
|
||||||
{ startIndex: 7, scopes: 'number.js' },
|
|
||||||
{ startIndex: 10, scopes: '' },
|
|
||||||
{ startIndex: 11, scopes: 'delimiter.bracket.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '[1,2,3]',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'delimiter.array.js' },
|
|
||||||
{ startIndex: 1, scopes: 'number.js' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: 'number.js' },
|
|
||||||
{ startIndex: 4, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 5, scopes: 'number.js' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.array.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'foo(123);',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 3, scopes: 'delimiter.parenthesis.js' },
|
|
||||||
{ startIndex: 4, scopes: 'number.js' },
|
|
||||||
{ startIndex: 7, scopes: 'delimiter.parenthesis.js' },
|
|
||||||
{ startIndex: 8, scopes: 'delimiter.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: '{a:{b:[]}}',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'delimiter.bracket.js' },
|
|
||||||
{ startIndex: 1, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: 'delimiter.bracket.js' },
|
|
||||||
{ startIndex: 4, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 5, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 6, scopes: 'delimiter.array.js' },
|
|
||||||
{ startIndex: 8, scopes: 'delimiter.bracket.js' }
|
|
||||||
]}],
|
|
||||||
|
|
||||||
[{
|
|
||||||
line: 'x = "[{()}]"',
|
|
||||||
tokens: [
|
|
||||||
{ startIndex: 0, scopes: 'identifier.js' },
|
|
||||||
{ startIndex: 1, scopes: '' },
|
|
||||||
{ startIndex: 2, scopes: 'delimiter.js' },
|
|
||||||
{ startIndex: 3, scopes: '' },
|
|
||||||
{ startIndex: 4, scopes: 'string.js' }
|
|
||||||
]}]
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
})
|
|
@ -1,163 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* 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 * as ts from './lib/typescriptServices';
|
|
||||||
|
|
||||||
export enum Language {
|
|
||||||
TypeScript,
|
|
||||||
EcmaScript5
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createTokenizationSupport(language: Language): monaco.languages.TokensProvider {
|
|
||||||
|
|
||||||
var classifier = ts.createClassifier(),
|
|
||||||
bracketTypeTable = language === Language.TypeScript ? tsBracketTypeTable : jsBracketTypeTable,
|
|
||||||
tokenTypeTable = language === Language.TypeScript ? tsTokenTypeTable : jsTokenTypeTable;
|
|
||||||
|
|
||||||
return {
|
|
||||||
getInitialState: () => new State(language, ts.EndOfLineState.None, false),
|
|
||||||
tokenize: (line, state) => tokenize(bracketTypeTable, tokenTypeTable, classifier, <State>state, line)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class State implements monaco.languages.IState {
|
|
||||||
|
|
||||||
public language: Language;
|
|
||||||
public eolState: ts.EndOfLineState;
|
|
||||||
public inJsDocComment: boolean;
|
|
||||||
|
|
||||||
constructor(language: Language, eolState: ts.EndOfLineState, inJsDocComment: boolean) {
|
|
||||||
this.language = language;
|
|
||||||
this.eolState = eolState;
|
|
||||||
this.inJsDocComment = inJsDocComment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public clone(): State {
|
|
||||||
return new State(this.language, this.eolState, this.inJsDocComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
public equals(other: monaco.languages.IState): boolean {
|
|
||||||
if (other === this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!other || !(other instanceof State)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.eolState !== (<State>other).eolState) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.inJsDocComment !== (<State>other).inJsDocComment) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenize(bracketTypeTable: { [i: number]: string }, tokenTypeTable: { [i: number]: string },
|
|
||||||
classifier: ts.Classifier, state: State, text: string): monaco.languages.ILineTokens {
|
|
||||||
|
|
||||||
// Create result early and fill in tokens
|
|
||||||
var ret = {
|
|
||||||
tokens: <monaco.languages.IToken[]>[],
|
|
||||||
endState: new State(state.language, ts.EndOfLineState.None, false)
|
|
||||||
};
|
|
||||||
|
|
||||||
function appendFn(startIndex: number, type: string): void {
|
|
||||||
if (ret.tokens.length === 0 || ret.tokens[ret.tokens.length - 1].scopes !== type) {
|
|
||||||
ret.tokens.push({
|
|
||||||
startIndex: startIndex,
|
|
||||||
scopes: type
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isTypeScript = state.language === Language.TypeScript;
|
|
||||||
|
|
||||||
// shebang statement, #! /bin/node
|
|
||||||
if (!isTypeScript && checkSheBang(0, text, appendFn)) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = classifier.getClassificationsForLine(text, state.eolState, true),
|
|
||||||
offset = 0;
|
|
||||||
|
|
||||||
ret.endState.eolState = result.finalLexState;
|
|
||||||
ret.endState.inJsDocComment = result.finalLexState === ts.EndOfLineState.InMultiLineCommentTrivia && (state.inJsDocComment || /\/\*\*.*$/.test(text));
|
|
||||||
|
|
||||||
for (let entry of result.entries) {
|
|
||||||
|
|
||||||
var type: string;
|
|
||||||
|
|
||||||
if (entry.classification === ts.TokenClass.Punctuation) {
|
|
||||||
// punctions: check for brackets: (){}[]
|
|
||||||
var ch = text.charCodeAt(offset);
|
|
||||||
type = bracketTypeTable[ch] || tokenTypeTable[entry.classification];
|
|
||||||
appendFn(offset, type);
|
|
||||||
|
|
||||||
} else if (entry.classification === ts.TokenClass.Comment) {
|
|
||||||
// comments: check for JSDoc, block, and line comments
|
|
||||||
if (ret.endState.inJsDocComment || /\/\*\*.*\*\//.test(text.substr(offset, entry.length))) {
|
|
||||||
appendFn(offset, isTypeScript ? 'comment.doc.ts' : 'comment.doc.js');
|
|
||||||
} else {
|
|
||||||
appendFn(offset, isTypeScript ? 'comment.ts' : 'comment.js');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// everything else
|
|
||||||
appendFn(offset,
|
|
||||||
tokenTypeTable[entry.classification] || '');
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += entry.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface INumberStringDictionary {
|
|
||||||
[idx: number]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var tsBracketTypeTable: INumberStringDictionary = Object.create(null);
|
|
||||||
tsBracketTypeTable['('.charCodeAt(0)] = 'delimiter.parenthesis.ts';
|
|
||||||
tsBracketTypeTable[')'.charCodeAt(0)] = 'delimiter.parenthesis.ts';
|
|
||||||
tsBracketTypeTable['{'.charCodeAt(0)] = 'delimiter.bracket.ts';
|
|
||||||
tsBracketTypeTable['}'.charCodeAt(0)] = 'delimiter.bracket.ts';
|
|
||||||
tsBracketTypeTable['['.charCodeAt(0)] = 'delimiter.array.ts';
|
|
||||||
tsBracketTypeTable[']'.charCodeAt(0)] = 'delimiter.array.ts';
|
|
||||||
|
|
||||||
var tsTokenTypeTable: INumberStringDictionary = Object.create(null);
|
|
||||||
tsTokenTypeTable[ts.TokenClass.Identifier] = 'identifier.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.Keyword] = 'keyword.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.Operator] = 'delimiter.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.Punctuation] = 'delimiter.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.NumberLiteral] = 'number.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.RegExpLiteral] = 'regexp.ts';
|
|
||||||
tsTokenTypeTable[ts.TokenClass.StringLiteral] = 'string.ts';
|
|
||||||
|
|
||||||
var jsBracketTypeTable: INumberStringDictionary = Object.create(null);
|
|
||||||
jsBracketTypeTable['('.charCodeAt(0)] = 'delimiter.parenthesis.js';
|
|
||||||
jsBracketTypeTable[')'.charCodeAt(0)] = 'delimiter.parenthesis.js';
|
|
||||||
jsBracketTypeTable['{'.charCodeAt(0)] = 'delimiter.bracket.js';
|
|
||||||
jsBracketTypeTable['}'.charCodeAt(0)] = 'delimiter.bracket.js';
|
|
||||||
jsBracketTypeTable['['.charCodeAt(0)] = 'delimiter.array.js';
|
|
||||||
jsBracketTypeTable[']'.charCodeAt(0)] = 'delimiter.array.js';
|
|
||||||
|
|
||||||
var jsTokenTypeTable: INumberStringDictionary = Object.create(null);
|
|
||||||
jsTokenTypeTable[ts.TokenClass.Identifier] = 'identifier.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.Keyword] = 'keyword.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.Operator] = 'delimiter.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.Punctuation] = 'delimiter.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.NumberLiteral] = 'number.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.RegExpLiteral] = 'regexp.js';
|
|
||||||
jsTokenTypeTable[ts.TokenClass.StringLiteral] = 'string.js';
|
|
||||||
|
|
||||||
|
|
||||||
function checkSheBang(deltaOffset: number, line: string, appendFn: (startIndex: number, type: string) => void): boolean {
|
|
||||||
if (line.indexOf('#!') === 0) {
|
|
||||||
appendFn(deltaOffset, 'comment.shebang');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
var requirejs = require("requirejs");
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
requirejs.config({
|
|
||||||
baseUrl: 'release/dev',
|
|
||||||
paths: {
|
|
||||||
'vs/language/typescript': path.join(__dirname, '/../release/dev')
|
|
||||||
},
|
|
||||||
nodeRequire: require
|
|
||||||
});
|
|
||||||
|
|
||||||
// Workaround for TypeScript
|
|
||||||
process.browser = true;
|
|
||||||
|
|
||||||
requirejs([
|
|
||||||
'vs/language/typescript/test/tokenization.test'
|
|
||||||
], function () {
|
|
||||||
run(); // We can launch the tests!
|
|
||||||
});
|
|
@ -1,3 +0,0 @@
|
|||||||
--delay
|
|
||||||
--ui tdd
|
|
||||||
test/all.js
|
|
Loading…
Reference in New Issue