Merge remote-tracking branch 'origin/master' into pr/ALANVF/59
commit
22d999d519
@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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';
|
||||
|
||||
registerLanguage({
|
||||
id: 'graphql',
|
||||
extensions: ['.graphql', '.gql'],
|
||||
aliases: ['GraphQL', 'graphql', 'gql'],
|
||||
mimetypes: ['application/graphql'],
|
||||
loader: () => import('./graphql')
|
||||
});
|
@ -0,0 +1,143 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 '../test/testRunner';
|
||||
|
||||
testTokenization('graphql', [
|
||||
// Keywords
|
||||
[{
|
||||
line: 'scalar Date',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.gql' },
|
||||
{ startIndex: 6, type: '' },
|
||||
{ startIndex: 7, type: 'type.identifier.gql' },
|
||||
]
|
||||
}],
|
||||
|
||||
// Root schema definition
|
||||
[{
|
||||
line: 'schema { query: Query, mutation: Mutation subscription: Subscription }',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "keyword.gql" },
|
||||
{ startIndex: 6, type: "" },
|
||||
{ startIndex: 7, type: "delimiter.curly.gql" },
|
||||
{ startIndex: 8, type: "" },
|
||||
{ startIndex: 9, type: "keyword.gql" }, // this should be identifier
|
||||
{ startIndex: 14, type: "operator.gql" },
|
||||
{ startIndex: 15, type: "" },
|
||||
{ startIndex: 16, type: "type.identifier.gql" },
|
||||
{ startIndex: 21, type: "delimiter.gql" },
|
||||
{ startIndex: 22, type: "" },
|
||||
{ startIndex: 23, type: "keyword.gql" }, // this should be identifier
|
||||
{ startIndex: 31, type: "operator.gql" },
|
||||
{ startIndex: 32, type: "" },
|
||||
{ startIndex: 33, type: "type.identifier.gql" },
|
||||
{ startIndex: 41, type: "" },
|
||||
{ startIndex: 42, type: "keyword.gql" }, // this should be identifier
|
||||
{ startIndex: 54, type: "operator.gql" },
|
||||
{ startIndex: 55, type: "" },
|
||||
{ startIndex: 56, type: "type.identifier.gql" },
|
||||
{ startIndex: 68, type: "" },
|
||||
{ startIndex: 69, type: "delimiter.curly.gql" },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: `query testQuery($intValue:Int=3){value(arg:{string:"string" int:$intValue}){field1 field2}}`,
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "keyword.gql" }, // 'query'
|
||||
{ startIndex: 5, type: "" }, // ' '
|
||||
{ startIndex: 6, type: "identifier.gql" }, // 'testQuery'
|
||||
{ startIndex: 15, type: "delimiter.parenthesis.gql" }, // '('
|
||||
{ startIndex: 16, type: "identifier.gql" }, // '$intValue'
|
||||
{ startIndex: 25, type: "operator.gql" }, // ':'
|
||||
{ startIndex: 26, type: "keyword.gql" }, // 'Int'
|
||||
{ startIndex: 29, type: "operator.gql" }, // '='
|
||||
{ startIndex: 30, type: "number.gql" }, // '3'
|
||||
{ startIndex: 31, type: "delimiter.parenthesis.gql" }, // ')'
|
||||
{ startIndex: 32, type: "delimiter.curly.gql" }, // '{'
|
||||
{ startIndex: 33, type: "identifier.gql" }, // 'value'
|
||||
{ startIndex: 38, type: "delimiter.parenthesis.gql" }, // '('
|
||||
{ startIndex: 39, type: "identifier.gql" }, // 'arg'
|
||||
{ startIndex: 42, type: "operator.gql" }, // ':'
|
||||
{ startIndex: 43, type: "delimiter.curly.gql" }, // '{'
|
||||
{ startIndex: 44, type: "identifier.gql" }, // 'string'
|
||||
{ startIndex: 50, type: "operator.gql" }, // ':'
|
||||
{ startIndex: 51, type: "string.quote.gql" }, // '"'
|
||||
{ startIndex: 52, type: "string.gql" }, // 'string'
|
||||
{ startIndex: 58, type: "string.quote.gql" }, // '"'
|
||||
{ startIndex: 59, type: "" }, // ' '
|
||||
{ startIndex: 60, type: "identifier.gql" }, // 'int'
|
||||
{ startIndex: 63, type: "operator.gql" }, // ':'
|
||||
{ startIndex: 64, type: "identifier.gql" }, // '$intValue'
|
||||
{ startIndex: 73, type: "delimiter.curly.gql" }, // '}'
|
||||
{ startIndex: 74, type: "delimiter.parenthesis.gql" }, // ')'
|
||||
{ startIndex: 75, type: "delimiter.curly.gql" }, // '{'
|
||||
{ startIndex: 76, type: "identifier.gql" }, // 'field1'
|
||||
{ startIndex: 82, type: "" }, // ' '
|
||||
{ startIndex: 83, type: "identifier.gql" }, // 'field2'
|
||||
{ startIndex: 89, type: "delimiter.curly.gql" }, // '}}'
|
||||
],
|
||||
}],
|
||||
|
||||
// More complex test:
|
||||
// """
|
||||
// Node interface
|
||||
// - allows (re)fetch arbitrary entity only by ID
|
||||
// """
|
||||
// interface Node {
|
||||
// id: ID!
|
||||
// }
|
||||
[
|
||||
{
|
||||
line: '"""',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "string.gql" }
|
||||
],
|
||||
},
|
||||
{
|
||||
line: 'This is MarkDown',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "" }
|
||||
],
|
||||
},
|
||||
{
|
||||
line: '"""',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "string.gql" }
|
||||
],
|
||||
},
|
||||
{
|
||||
line: 'interface Node {',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "keyword.gql" },
|
||||
{ startIndex: 9, type: "" },
|
||||
{ startIndex: 10, type: "type.identifier.gql" },
|
||||
{ startIndex: 14, type: "" },
|
||||
{ startIndex: 15, type: "delimiter.curly.gql" },
|
||||
],
|
||||
},
|
||||
{
|
||||
line: ' id: ID!',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "" },
|
||||
{ startIndex: 2, type: "identifier.gql" },
|
||||
{ startIndex: 4, type: "operator.gql" },
|
||||
{ startIndex: 5, type: "" },
|
||||
{ startIndex: 6, type: "keyword.gql" },
|
||||
{ startIndex: 8, type: "operator.gql" },
|
||||
],
|
||||
},
|
||||
{
|
||||
line: '}',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: "delimiter.curly.gql", },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
]);
|
@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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: '#'
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"""', close: '"""', notIn: ['string', 'comment'] },
|
||||
{ open: '"', close: '"', notIn: ['string', 'comment'] },
|
||||
],
|
||||
surroundingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"""', close: '"""' },
|
||||
{ open: '"', close: '"' },
|
||||
],
|
||||
folding: {
|
||||
offSide: true
|
||||
}
|
||||
};
|
||||
|
||||
export const language = <ILanguage>{
|
||||
// Set defaultToken to invalid to see what you do not tokenize yet
|
||||
defaultToken: 'invalid',
|
||||
tokenPostfix: '.gql',
|
||||
|
||||
keywords: [
|
||||
'null', 'true', 'false',
|
||||
'query', 'mutation', 'subscription',
|
||||
'extend', 'schema', 'directive',
|
||||
'scalar', 'type', 'interface', 'union', 'enum', 'input', 'implements',
|
||||
'fragment', 'on',
|
||||
],
|
||||
|
||||
typeKeywords: ['Int', 'Float', 'String', 'Boolean', 'ID'],
|
||||
|
||||
directiveLocations: [
|
||||
'SCHEMA', 'SCALAR', 'OBJECT', 'FIELD_DEFINITION', 'ARGUMENT_DEFINITION',
|
||||
'INTERFACE', 'UNION', 'ENUM', 'ENUM_VALUE', 'INPUT_OBJECT', 'INPUT_FIELD_DEFINITION',
|
||||
'QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION',
|
||||
'FRAGMENT_SPREAD', 'INLINE_FRAGMENT', 'VARIABLE_DEFINITION',
|
||||
],
|
||||
|
||||
operators: ['=', '!', '?', ':', '&', '|'],
|
||||
|
||||
// we include these common regular expressions
|
||||
symbols: /[=!?:&|]+/,
|
||||
|
||||
// https://facebook.github.io/graphql/draft/#sec-String-Value
|
||||
escapes: /\\(?:["\\\/bfnrt]|u[0-9A-Fa-f]{4})/,
|
||||
|
||||
// The main tokenizer for our languages
|
||||
tokenizer: {
|
||||
root: [
|
||||
// identifiers and keywords
|
||||
[
|
||||
/[a-z_$][\w$]*/,
|
||||
{
|
||||
cases: {
|
||||
'@keywords': 'keyword',
|
||||
'@default': 'identifier',
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
/[A-Z][\w\$]*/,
|
||||
{
|
||||
cases: {
|
||||
'@typeKeywords': 'keyword',
|
||||
'@default': 'type.identifier',
|
||||
},
|
||||
},
|
||||
], // to show class names nicely
|
||||
|
||||
// whitespace
|
||||
{ include: '@whitespace' },
|
||||
|
||||
// delimiters and operators
|
||||
[/[{}()\[\]]/, '@brackets'],
|
||||
[
|
||||
/@symbols/,
|
||||
{ cases: { '@operators': 'operator', '@default': '' } },
|
||||
],
|
||||
|
||||
// @ annotations.
|
||||
// As an example, we emit a debugging log message on these tokens.
|
||||
// Note: message are supressed during the first load -- change some lines to see them.
|
||||
[
|
||||
/@\s*[a-zA-Z_\$][\w\$]*/,
|
||||
{ token: 'annotation', log: 'annotation token: $0' },
|
||||
],
|
||||
|
||||
// numbers
|
||||
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
|
||||
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
|
||||
[/\d+/, 'number'],
|
||||
|
||||
// delimiter: after number because of .\d floats
|
||||
[/[;,.]/, 'delimiter'],
|
||||
|
||||
[/"""/,
|
||||
{ token: 'string', next: '@mlstring', nextEmbedded: 'markdown' }
|
||||
],
|
||||
|
||||
// strings
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],
|
||||
],
|
||||
|
||||
mlstring: [
|
||||
[/[^"]+/, 'string'],
|
||||
['"""', { token: 'string', next: '@pop', nextEmbedded: '@pop' }]
|
||||
],
|
||||
|
||||
string: [
|
||||
[/[^\\"]+/, 'string'],
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/\\./, 'string.escape.invalid'],
|
||||
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }],
|
||||
],
|
||||
|
||||
whitespace: [[/[ \t\r\n]+/, ''], [/#.*$/, 'comment']],
|
||||
},
|
||||
};
|
@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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';
|
||||
|
||||
registerLanguage({
|
||||
id: 'kotlin',
|
||||
extensions: ['.kt'],
|
||||
aliases: ['Kotlin', 'kotlin'],
|
||||
mimetypes: ['text/x-kotlin-source', 'text/x-kotlin'],
|
||||
loader: () => import('./kotlin')
|
||||
});
|
@ -0,0 +1,671 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 '../test/testRunner';
|
||||
|
||||
testTokenization('kotlin', [
|
||||
// inline reified function
|
||||
[{
|
||||
line: 'inline fun <reified T : Any> foo()',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.inline.kt' },
|
||||
{ startIndex: 6, type: '' },
|
||||
{ startIndex: 7, type: 'keyword.fun.kt' },
|
||||
{ startIndex: 10, type: '' },
|
||||
{ startIndex: 11, type: 'delimiter.angle.kt' },
|
||||
{ startIndex: 12, type: 'keyword.reified.kt' },
|
||||
{ startIndex: 19, type: '' },
|
||||
{ startIndex: 20, type: 'type.identifier.kt' },
|
||||
{ startIndex: 21, type: '' },
|
||||
{ startIndex: 22, type: 'delimiter.kt' },
|
||||
{ startIndex: 23, type: '' },
|
||||
{ startIndex: 24, type: 'type.identifier.kt' },
|
||||
{ startIndex: 27, type: 'delimiter.angle.kt' },
|
||||
{ startIndex: 28, type: '' },
|
||||
{ startIndex: 29, type: 'identifier.kt' },
|
||||
{ startIndex: 32, type: 'delimiter.parenthesis.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
// Val declaration and assignment
|
||||
[{
|
||||
line: 'val x: X=5',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.val.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: 'delimiter.kt' },
|
||||
{ startIndex: 6, type: '' },
|
||||
{ startIndex: 7, type: 'type.identifier.kt' },
|
||||
{ startIndex: 8, type: 'delimiter.kt' },
|
||||
{ startIndex: 9, type: 'number.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
// Comments - single line
|
||||
[{
|
||||
line: '//',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: ' // a comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: '' },
|
||||
{ startIndex: 4, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// Broken nested tokens due to invalid comment tokenization
|
||||
[{
|
||||
line: '/* //*/ a',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '// a comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '//sticky comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '/almost a comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'delimiter.kt' },
|
||||
{ startIndex: 1, type: 'identifier.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'identifier.kt' },
|
||||
{ startIndex: 9, type: '' },
|
||||
{ startIndex: 10, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1 / 2; /* comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: '' },
|
||||
{ startIndex: 2, type: 'delimiter.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'number.kt' },
|
||||
{ startIndex: 5, type: 'delimiter.kt' },
|
||||
{ startIndex: 6, type: '' },
|
||||
{ startIndex: 7, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// [{
|
||||
// line: 'var x = 1 // my comment // is a nice one',
|
||||
// tokens: [
|
||||
// { startIndex: 0, type: 'keyword.var.kt' },
|
||||
// { startIndex: 3, type: '' },
|
||||
// { startIndex: 4, type: 'identifier.kt' },
|
||||
// { startIndex: 5, type: '' },
|
||||
// { startIndex: 6, type: 'delimiter.kt' },
|
||||
// { startIndex: 7, type: '' },
|
||||
// { startIndex: 8, type: 'number.kt' },
|
||||
// { startIndex: 9, type: '' },
|
||||
// { startIndex: 10, type: 'comment.kt' },
|
||||
// { startIndex: 12, type: '' },
|
||||
// { startIndex: 13, type: 'comment.kt' }
|
||||
// ]
|
||||
// }],
|
||||
|
||||
// Comments - range comment, single line
|
||||
[{
|
||||
line: '/* a simple comment */',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: 'var x = /* a simple comment */ 1',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.var.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: '' },
|
||||
{ startIndex: 6, type: 'delimiter.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'comment.kt' },
|
||||
{ startIndex: 30, type: '' },
|
||||
{ startIndex: 31, type: 'number.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: 'var x = /* comment */ 1; */',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.var.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: '' },
|
||||
{ startIndex: 6, type: 'delimiter.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'comment.kt' },
|
||||
{ startIndex: 21, type: '' },
|
||||
{ startIndex: 22, type: 'number.kt' },
|
||||
{ startIndex: 23, type: 'delimiter.kt' },
|
||||
{ startIndex: 24, type: '' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: 'x = /**/',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'identifier.kt' },
|
||||
{ startIndex: 1, type: '' },
|
||||
{ startIndex: 2, type: 'delimiter.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'comment.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: 'var x = /** start a Java Doc comment',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.var.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: '' },
|
||||
{ startIndex: 6, type: 'delimiter.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'comment.doc.kt' }
|
||||
]
|
||||
}, {
|
||||
line: ' a ',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.doc.kt' }
|
||||
]
|
||||
}, {
|
||||
line: 'and end it */ 2',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.doc.kt' },
|
||||
{ startIndex: 13, type: '' },
|
||||
{ startIndex: 14, type: 'number.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '/** start of Java Doc',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.doc.kt' }
|
||||
]
|
||||
}, {
|
||||
line: 'a comment between without a star',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.doc.kt' }
|
||||
]
|
||||
}, {
|
||||
line: 'end of multiline comment*/',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'comment.doc.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// Keywords
|
||||
[{
|
||||
line: 'package test class Program { fun main(vararg args: String) {} } }',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.package.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'identifier.kt' },
|
||||
{ startIndex: 12, type: '' },
|
||||
{ startIndex: 13, type: 'keyword.class.kt' },
|
||||
{ startIndex: 18, type: '' },
|
||||
{ startIndex: 19, type: 'type.identifier.kt' },
|
||||
{ startIndex: 26, type: '' },
|
||||
{ startIndex: 27, type: 'delimiter.curly.kt' },
|
||||
{ startIndex: 28, type: '' },
|
||||
{ startIndex: 29, type: 'keyword.fun.kt' },
|
||||
{ startIndex: 32, type: '' },
|
||||
{ startIndex: 33, type: 'identifier.kt' },
|
||||
{ startIndex: 37, type: 'delimiter.parenthesis.kt' },
|
||||
{ startIndex: 38, type: 'keyword.vararg.kt' },
|
||||
{ startIndex: 44, type: '' },
|
||||
{ startIndex: 45, type: 'identifier.kt' },
|
||||
{ startIndex: 49, type: 'delimiter.kt' },
|
||||
{ startIndex: 50, type: '' },
|
||||
{ startIndex: 51, type: 'type.identifier.kt' },
|
||||
{ startIndex: 57, type: 'delimiter.parenthesis.kt' },
|
||||
{ startIndex: 58, type: '' },
|
||||
{ startIndex: 59, type: 'delimiter.curly.kt' },
|
||||
{ startIndex: 61, type: '' },
|
||||
{ startIndex: 62, type: 'delimiter.curly.kt' },
|
||||
{ startIndex: 63, type: '' },
|
||||
{ startIndex: 64, type: 'delimiter.curly.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// Numbers
|
||||
[{
|
||||
line: '0',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0.10',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0x',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0x123',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.hex.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0x5_2',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.hex.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '023L',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.octal.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0123l',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.octal.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '05_2',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.octal.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0b1010_0101',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.binary.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0B001',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.binary.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '10e3',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '10f',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5e3',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5e-3',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5E3',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5E-3',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5F',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5f',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5D',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23.5d',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72E3D',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72E3d',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72E-3d',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72e3D',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72e3d',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '1.72e-3d',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23L',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '23l',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0_52',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '5_2',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '5_______2',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '3_.1415F',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'identifier.kt' },
|
||||
{ startIndex: 2, type: 'delimiter.kt' },
|
||||
{ startIndex: 3, type: 'number.float.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '3._1415F',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'delimiter.kt' },
|
||||
{ startIndex: 2, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '999_99_9999_L',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 11, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '52_',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 2, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0_x52',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0x_52',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0x52_',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.hex.kt' },
|
||||
{ startIndex: 4, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '052_',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.octal.kt' },
|
||||
{ startIndex: 3, type: 'identifier.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0+0',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: 'delimiter.kt' },
|
||||
{ startIndex: 2, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '100+10',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 3, type: 'delimiter.kt' },
|
||||
{ startIndex: 4, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '0 + 0',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'number.kt' },
|
||||
{ startIndex: 1, type: '' },
|
||||
{ startIndex: 2, type: 'delimiter.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'number.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// single line Strings
|
||||
[{
|
||||
line: 'var s = "I\'m a Kotlin String"',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.var.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: '' },
|
||||
{ startIndex: 6, type: 'delimiter.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'string.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: 'var s = "concatenated" + " String"',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'keyword.var.kt' },
|
||||
{ startIndex: 3, type: '' },
|
||||
{ startIndex: 4, type: 'identifier.kt' },
|
||||
{ startIndex: 5, type: '' },
|
||||
{ startIndex: 6, type: 'delimiter.kt' },
|
||||
{ startIndex: 7, type: '' },
|
||||
{ startIndex: 8, type: 'string.kt' },
|
||||
{ startIndex: 22, type: '' },
|
||||
{ startIndex: 23, type: 'delimiter.kt' },
|
||||
{ startIndex: 24, type: '' },
|
||||
{ startIndex: 25, type: 'string.kt' },
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '"quote in a string"',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'string.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '"escaping \\"quotes\\" is cool"',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'string.kt' },
|
||||
{ startIndex: 10, type: 'string.escape.kt' },
|
||||
{ startIndex: 12, type: 'string.kt' },
|
||||
{ startIndex: 18, type: 'string.escape.kt' },
|
||||
{ startIndex: 20, type: 'string.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '"\\"',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'string.invalid.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
// Annotations
|
||||
[{
|
||||
line: '@',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: '' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '@Inject',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'annotation.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '@SuppressWarnings("aString")',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'annotation.kt' },
|
||||
{ startIndex: 17, type: 'delimiter.parenthesis.kt' },
|
||||
{ startIndex: 18, type: 'string.kt' },
|
||||
{ startIndex: 27, type: 'delimiter.parenthesis.kt' }
|
||||
]
|
||||
}],
|
||||
|
||||
[{
|
||||
line: '@ AnnotationWithKeywordAfter private',
|
||||
tokens: [
|
||||
{ startIndex: 0, type: 'annotation.kt' },
|
||||
{ startIndex: 28, type: '' },
|
||||
{ startIndex: 29, type: 'keyword.private.kt' }
|
||||
]
|
||||
}]
|
||||
]);
|
||||
|
@ -0,0 +1,158 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 = {
|
||||
// the default separators except `@$`
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
||||
comments: {
|
||||
lineComment: '//',
|
||||
blockComment: ['/*', '*/'],
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')'],
|
||||
],
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"' },
|
||||
{ open: '\'', close: '\'' },
|
||||
],
|
||||
surroundingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"' },
|
||||
{ open: '\'', close: '\'' },
|
||||
{ open: '<', close: '>' },
|
||||
],
|
||||
folding: {
|
||||
markers: {
|
||||
start: new RegExp("^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))"),
|
||||
end: new RegExp("^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const language = <ILanguage>{
|
||||
defaultToken: '',
|
||||
tokenPostfix: '.kt',
|
||||
|
||||
keywords: [
|
||||
'as', 'as?', 'break', 'class', 'continue', 'do', 'else', 'false', 'for', 'fun', 'if',
|
||||
'in', '!in', 'interface', 'is', '!is', 'null', 'object', 'package', 'return', 'super',
|
||||
'this', 'throw', 'true', 'try', 'typealias', 'val', 'var', 'when', 'while', 'by',
|
||||
'catch', 'constructor', 'delegate', 'dynamic', 'field', 'file', 'finally', 'get',
|
||||
'import', 'init', 'param', 'property', 'receiver', 'set', 'setparam', 'where', 'actual',
|
||||
'abstract','annotation', 'companion', 'const', 'crossinline', 'data', 'enum', 'expect',
|
||||
'external', 'final', 'infix', 'inline', 'inner', 'internal', 'lateinit', 'noinline',
|
||||
'open', 'operator', 'out', 'override', 'private', 'protected', 'public', 'reified',
|
||||
'sealed', 'suspend', 'tailrec', 'vararg', 'field', 'it'
|
||||
],
|
||||
|
||||
operators: [
|
||||
'+', '-', '*', '/', '%', '=', '+=', '-=', '*=', '/=',
|
||||
'%=', '++', '--', '&&', '||', '!', '==', '!=', '===',
|
||||
'!==', '>', '<', '<=', '>=', '[', ']', '!!', '?.', '?:',
|
||||
'::', '..', ':', '?', '->', '@', ';', '$', '_'
|
||||
],
|
||||
|
||||
// we include these common regular expressions
|
||||
symbols: /[=><!~?:&|+\-*\/\^%]+/,
|
||||
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
||||
digits: /\d+(_+\d+)*/,
|
||||
octaldigits: /[0-7]+(_+[0-7]+)*/,
|
||||
binarydigits: /[0-1]+(_+[0-1]+)*/,
|
||||
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
|
||||
|
||||
// The main tokenizer for our languages
|
||||
tokenizer: {
|
||||
|
||||
root: [
|
||||
// class name highlighting
|
||||
[/[A-Z][\w\$]*/, 'type.identifier' ],
|
||||
|
||||
// identifiers and keywords
|
||||
[/[a-zA-Z_$][\w$]*/, {
|
||||
cases: {
|
||||
'@keywords': { token: 'keyword.$0' },
|
||||
'@default': 'identifier'
|
||||
}
|
||||
}],
|
||||
|
||||
// whitespace
|
||||
{ include: '@whitespace' },
|
||||
|
||||
// delimiters and operators
|
||||
[/[{}()\[\]]/, '@brackets'],
|
||||
[/[<>](?!@symbols)/, '@brackets'],
|
||||
[/@symbols/, {
|
||||
cases: {
|
||||
'@operators': 'delimiter',
|
||||
'@default': ''
|
||||
}
|
||||
}],
|
||||
|
||||
// @ annotations.
|
||||
[/@\s*[a-zA-Z_\$][\w\$]*/, 'annotation'],
|
||||
|
||||
// numbers
|
||||
[/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'],
|
||||
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'],
|
||||
[/0[xX](@hexdigits)[Ll]?/, 'number.hex'],
|
||||
[/0(@octaldigits)[Ll]?/, 'number.octal'],
|
||||
[/0[bB](@binarydigits)[Ll]?/, 'number.binary'],
|
||||
[/(@digits)[fFdD]/, 'number.float'],
|
||||
[/(@digits)[lL]?/, 'number'],
|
||||
|
||||
// delimiter: after number because of .\d floats
|
||||
[/[;,.]/, 'delimiter'],
|
||||
|
||||
// strings
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/"/, 'string', '@string'],
|
||||
|
||||
// characters
|
||||
[/'[^\\']'/, 'string'],
|
||||
[/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
|
||||
[/'/, 'string.invalid']
|
||||
],
|
||||
|
||||
whitespace: [
|
||||
[/[ \t\r\n]+/, ''],
|
||||
[/\/\*\*(?!\/)/, 'comment.doc', '@javadoc'],
|
||||
[/\/\*/, 'comment', '@comment'],
|
||||
[/\/\/.*$/, 'comment'],
|
||||
],
|
||||
|
||||
comment: [
|
||||
[/[^\/*]+/, 'comment'],
|
||||
[/\*\//, 'comment', '@pop'],
|
||||
[/[\/*]/, 'comment']
|
||||
],
|
||||
//Identical copy of comment above, except for the addition of .doc
|
||||
javadoc: [
|
||||
[/[^\/*]+/, 'comment.doc'],
|
||||
// [/\/\*/, 'comment.doc', '@push' ], // nested comment not allowed :-(
|
||||
[/\/\*/, 'comment.doc.invalid'],
|
||||
[/\*\//, 'comment.doc', '@pop'],
|
||||
[/[\/*]/, 'comment.doc']
|
||||
],
|
||||
|
||||
string: [
|
||||
[/[^\\"]+/, 'string'],
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/\\./, 'string.escape.invalid'],
|
||||
[/"/, 'string', '@pop']
|
||||
],
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue