mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +01:00
Add support for Bicep language
This commit is contained in:
parent
0500e21d95
commit
999aa25f2a
4 changed files with 1214 additions and 0 deletions
13
src/bicep/bicep.contribution.ts
Normal file
13
src/bicep/bicep.contribution.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { registerLanguage } from '../_.contribution';
|
||||
|
||||
registerLanguage({
|
||||
id: 'bicep',
|
||||
extensions: ['.bicep'],
|
||||
aliases: ['Bicep'],
|
||||
loader: () => import('./bicep')
|
||||
});
|
||||
1069
src/bicep/bicep.test.ts
Normal file
1069
src/bicep/bicep.test.ts
Normal file
File diff suppressed because it is too large
Load diff
131
src/bicep/bicep.ts
Normal file
131
src/bicep/bicep.ts
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { languages } from '../fillers/monaco-editor-core';
|
||||
|
||||
const bounded = (text: string) => `\\b${text}\\b`;
|
||||
|
||||
const identifierStart = '[_a-zA-Z]';
|
||||
const identifierContinue = '[_a-zA-Z0-9]';
|
||||
const identifier = bounded(`${identifierStart}${identifierContinue}*`);
|
||||
|
||||
const keywords = [
|
||||
'targetScope',
|
||||
'resource',
|
||||
'module',
|
||||
'param',
|
||||
'var',
|
||||
'output',
|
||||
'for',
|
||||
'in',
|
||||
'if',
|
||||
'existing'
|
||||
];
|
||||
|
||||
const namedLiterals = ['true', 'false', 'null'];
|
||||
|
||||
const nonCommentWs = `[ \\t\\r\\n]`;
|
||||
|
||||
const numericLiteral = `[0-9]+`;
|
||||
|
||||
export const conf: languages.LanguageConfiguration = {
|
||||
comments: {
|
||||
lineComment: '//',
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
surroundingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: "'", close: "'" },
|
||||
{ open: "'''", close: "'''" }
|
||||
],
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: "'", close: "'", notIn: ['string', 'comment'] },
|
||||
{ open: "'''", close: "'''", notIn: ['string', 'comment'] }
|
||||
],
|
||||
autoCloseBefore: ":.,=}])' \n\t",
|
||||
indentationRules: {
|
||||
increaseIndentPattern: new RegExp(
|
||||
'^((?!\\/\\/).)*(\\{[^}"\'`]*|\\([^)"\'`]*|\\[[^\\]"\'`]*)$'
|
||||
),
|
||||
decreaseIndentPattern: new RegExp('^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]].*$')
|
||||
}
|
||||
};
|
||||
|
||||
export const language = <languages.IMonarchLanguage>{
|
||||
defaultToken: '',
|
||||
tokenPostfix: '.bicep',
|
||||
|
||||
brackets: [
|
||||
{ open: '{', close: '}', token: 'delimiter.curly' },
|
||||
{ open: '[', close: ']', token: 'delimiter.square' },
|
||||
{ open: '(', close: ')', token: 'delimiter.parenthesis' }
|
||||
],
|
||||
|
||||
symbols: /[=><!~?:&|+\-*/^%]+/,
|
||||
|
||||
keywords,
|
||||
namedLiterals,
|
||||
|
||||
escapes: `\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\\${)`,
|
||||
|
||||
tokenizer: {
|
||||
root: [{ include: '@expression' }, { include: '@whitespace' }],
|
||||
|
||||
stringVerbatim: [
|
||||
{ regex: `(|'|'')[^']`, action: { token: 'string' } },
|
||||
{ regex: `'''`, action: { token: 'string.quote', next: '@pop' } }
|
||||
],
|
||||
|
||||
stringLiteral: [
|
||||
{ regex: `\\\${`, action: { token: 'delimiter.bracket', next: '@bracketCounting' } },
|
||||
{ regex: `[^\\\\'$]+`, action: { token: 'string' } },
|
||||
{ regex: '@escapes', action: { token: 'string.escape' } },
|
||||
{ regex: `\\\\.`, action: { token: 'string.escape.invalid' } },
|
||||
{ regex: `'`, action: { token: 'string', next: '@pop' } }
|
||||
],
|
||||
|
||||
bracketCounting: [
|
||||
{ regex: `{`, action: { token: 'delimiter.bracket', next: '@bracketCounting' } },
|
||||
{ regex: `}`, action: { token: 'delimiter.bracket', next: '@pop' } },
|
||||
{ include: 'expression' }
|
||||
],
|
||||
|
||||
comment: [
|
||||
{ regex: `[^\\*]+`, action: { token: 'comment' } },
|
||||
{ regex: `\\*\\/`, action: { token: 'comment', next: '@pop' } },
|
||||
{ regex: `[\\/*]`, action: { token: 'comment' } }
|
||||
],
|
||||
|
||||
whitespace: [
|
||||
{ regex: nonCommentWs },
|
||||
{ regex: `\\/\\*`, action: { token: 'comment', next: '@comment' } },
|
||||
{ regex: `\\/\\/.*$`, action: { token: 'comment' } }
|
||||
],
|
||||
|
||||
expression: [
|
||||
{ regex: `'''`, action: { token: 'string.quote', next: '@stringVerbatim' } },
|
||||
{ regex: `'`, action: { token: 'string.quote', next: '@stringLiteral' } },
|
||||
{ regex: numericLiteral, action: { token: 'number' } },
|
||||
{
|
||||
regex: identifier,
|
||||
action: {
|
||||
cases: {
|
||||
'@keywords': { token: 'keyword' },
|
||||
'@namedLiterals': { token: 'keyword' },
|
||||
'@default': { token: 'identifier' }
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
@ -7,6 +7,7 @@ import './abap/abap.contribution';
|
|||
import './apex/apex.contribution';
|
||||
import './azcli/azcli.contribution';
|
||||
import './bat/bat.contribution';
|
||||
import './bicep/bicep.contribution';
|
||||
import './cameligo/cameligo.contribution';
|
||||
import './clojure/clojure.contribution';
|
||||
import './coffee/coffee.contribution';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue