mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
run prettier
This commit is contained in:
parent
9d8859a82d
commit
ec11002385
3 changed files with 1285 additions and 1304 deletions
1424
src/hcl/hcl.test.ts
1424
src/hcl/hcl.test.ts
File diff suppressed because it is too large
Load diff
209
src/hcl/hcl.ts
209
src/hcl/hcl.ts
|
|
@ -11,7 +11,7 @@ import ILanguage = monaco.languages.IMonarchLanguage;
|
|||
export const conf: IRichLanguageConfiguration = {
|
||||
comments: {
|
||||
lineComment: '//',
|
||||
blockComment: ['/*', '*/'],
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
|
|
@ -22,59 +22,59 @@ export const conf: IRichLanguageConfiguration = {
|
|||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '"', close: '"', notIn: ['string'] }
|
||||
],
|
||||
surroundingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"' },
|
||||
{ open: '"', close: '"' }
|
||||
]
|
||||
};
|
||||
|
||||
export const language = <ILanguage>{
|
||||
defaultToken: "",
|
||||
tokenPostfix: ".hcl",
|
||||
defaultToken: '',
|
||||
tokenPostfix: '.hcl',
|
||||
|
||||
keywords: [
|
||||
"var",
|
||||
"local",
|
||||
"path",
|
||||
"for_each",
|
||||
"any",
|
||||
"string",
|
||||
"number",
|
||||
"bool",
|
||||
"true",
|
||||
"false",
|
||||
"null",
|
||||
"if ",
|
||||
"else ",
|
||||
"endif ",
|
||||
"for ",
|
||||
"in",
|
||||
"endfor",
|
||||
'var',
|
||||
'local',
|
||||
'path',
|
||||
'for_each',
|
||||
'any',
|
||||
'string',
|
||||
'number',
|
||||
'bool',
|
||||
'true',
|
||||
'false',
|
||||
'null',
|
||||
'if ',
|
||||
'else ',
|
||||
'endif ',
|
||||
'for ',
|
||||
'in',
|
||||
'endfor'
|
||||
],
|
||||
|
||||
operators: [
|
||||
"=",
|
||||
">=",
|
||||
"<=",
|
||||
"==",
|
||||
"!=",
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"%",
|
||||
"&&",
|
||||
"||",
|
||||
"!",
|
||||
"<",
|
||||
">",
|
||||
"?",
|
||||
"...",
|
||||
":",
|
||||
'=',
|
||||
'>=',
|
||||
'<=',
|
||||
'==',
|
||||
'!=',
|
||||
'+',
|
||||
'-',
|
||||
'*',
|
||||
'/',
|
||||
'%',
|
||||
'&&',
|
||||
'||',
|
||||
'!',
|
||||
'<',
|
||||
'>',
|
||||
'?',
|
||||
'...',
|
||||
':'
|
||||
],
|
||||
|
||||
symbols: /[=><!~?:&|+\-*\/\^%]+/,
|
||||
|
|
@ -86,44 +86,20 @@ export const language = <ILanguage>{
|
|||
// highlight main blocks
|
||||
[
|
||||
/^@terraformMainBlocks([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
|
||||
[
|
||||
"type",
|
||||
"",
|
||||
"string",
|
||||
"",
|
||||
"string",
|
||||
"",
|
||||
"@brackets",
|
||||
],
|
||||
['type', '', 'string', '', 'string', '', '@brackets']
|
||||
],
|
||||
// highlight all the remaining blocks
|
||||
[
|
||||
/(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)(\{)/,
|
||||
[
|
||||
"identifier",
|
||||
"",
|
||||
"string",
|
||||
"",
|
||||
"string",
|
||||
"",
|
||||
"@brackets",
|
||||
],
|
||||
['identifier', '', 'string', '', 'string', '', '@brackets']
|
||||
],
|
||||
// highlight block
|
||||
[
|
||||
/(\w+[ \t]+)([ \t]*)([\w-]+|"[\w-]+"|)([ \t]*)([\w-]+|"[\w-]+"|)(=)(\{)/,
|
||||
[
|
||||
"identifier",
|
||||
"",
|
||||
"string",
|
||||
"",
|
||||
"operator",
|
||||
"",
|
||||
"@brackets",
|
||||
],
|
||||
['identifier', '', 'string', '', 'operator', '', '@brackets']
|
||||
],
|
||||
// terraform general highlight - shared with expressions
|
||||
{ include: "@terraform" },
|
||||
{ include: '@terraform' }
|
||||
],
|
||||
terraform: [
|
||||
// highlight terraform functions
|
||||
|
|
@ -133,81 +109,86 @@ export const language = <ILanguage>{
|
|||
/[a-zA-Z_]\w*-*/, // must work with variables such as foo-bar and also with negative numbers
|
||||
{
|
||||
cases: {
|
||||
"@keywords": { token: "keyword.$0" },
|
||||
"@default": "variable",
|
||||
},
|
||||
},
|
||||
'@keywords': { token: 'keyword.$0' },
|
||||
'@default': 'variable'
|
||||
}
|
||||
}
|
||||
],
|
||||
{ include: "@whitespace" },
|
||||
{ include: '@whitespace' },
|
||||
{ include: '@heredoc' },
|
||||
// delimiters and operators
|
||||
[/[{}()\[\]]/, "@brackets"],
|
||||
[/[<>](?!@symbols)/, "@brackets"],
|
||||
[/[{}()\[\]]/, '@brackets'],
|
||||
[/[<>](?!@symbols)/, '@brackets'],
|
||||
[
|
||||
/@symbols/,
|
||||
{
|
||||
cases: {
|
||||
"@operators": "operator",
|
||||
"@default": "",
|
||||
},
|
||||
},
|
||||
'@operators': 'operator',
|
||||
'@default': ''
|
||||
}
|
||||
}
|
||||
],
|
||||
// numbers
|
||||
[/\d*\d+[eE]([\-+]?\d+)?/, "number.float"],
|
||||
[/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
|
||||
[/\d[\d']*/, "number"],
|
||||
[/\d/, "number"],
|
||||
[/[;,.]/, "delimiter"], // delimiter: after number because of .\d floats
|
||||
[/\d*\d+[eE]([\-+]?\d+)?/, 'number.float'],
|
||||
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
|
||||
[/\d[\d']*/, 'number'],
|
||||
[/\d/, 'number'],
|
||||
[/[;,.]/, 'delimiter'], // delimiter: after number because of .\d floats
|
||||
// strings
|
||||
[/"/, "string", "@string"], // this will include expressions
|
||||
[/'/, "invalid"],
|
||||
[/"/, 'string', '@string'], // this will include expressions
|
||||
[/'/, 'invalid']
|
||||
],
|
||||
heredoc: [
|
||||
[
|
||||
/<<[-]*\s*["]?([\w\-]+)["]?/,
|
||||
{ token: 'string.heredoc.delimiter', next: '@heredocBody.$1' },
|
||||
],
|
||||
{ token: 'string.heredoc.delimiter', next: '@heredocBody.$1' }
|
||||
]
|
||||
],
|
||||
heredocBody: [
|
||||
[
|
||||
/^([\w\-]+)$/,
|
||||
{
|
||||
cases: {
|
||||
'$1==$S2': [{ token: 'string.heredoc.delimiter', next: '@popall' }],
|
||||
'@default': 'string.heredoc',
|
||||
},
|
||||
},
|
||||
'$1==$S2': [
|
||||
{
|
||||
token: 'string.heredoc.delimiter',
|
||||
next: '@popall'
|
||||
}
|
||||
],
|
||||
[/./, 'string.heredoc'],
|
||||
'@default': 'string.heredoc'
|
||||
}
|
||||
}
|
||||
],
|
||||
[/./, 'string.heredoc']
|
||||
],
|
||||
whitespace: [
|
||||
[/[ \t\r\n]+/, ""],
|
||||
[/\/\*/, "comment", "@comment"],
|
||||
[/\/\/.*$/, "comment"],
|
||||
[/#.*$/, "comment"],
|
||||
[/[ \t\r\n]+/, ''],
|
||||
[/\/\*/, 'comment', '@comment'],
|
||||
[/\/\/.*$/, 'comment'],
|
||||
[/#.*$/, 'comment']
|
||||
],
|
||||
comment: [
|
||||
[/[^\/*]+/, "comment"],
|
||||
[/\*\//, "comment", "@pop"],
|
||||
[/[\/*]/, "comment"],
|
||||
[/[^\/*]+/, 'comment'],
|
||||
[/\*\//, 'comment', '@pop'],
|
||||
[/[\/*]/, 'comment']
|
||||
],
|
||||
string: [
|
||||
[/\$\{/, { token: "delimiter", next: "@stringExpression" }],
|
||||
[/[^\\"\$]+/, "string"],
|
||||
[/@escapes/, "string.escape"],
|
||||
[/\\./, "string.escape.invalid"],
|
||||
[/"/, "string", "@popall"],
|
||||
[/\$\{/, { token: 'delimiter', next: '@stringExpression' }],
|
||||
[/[^\\"\$]+/, 'string'],
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/\\./, 'string.escape.invalid'],
|
||||
[/"/, 'string', '@popall']
|
||||
],
|
||||
stringInsideExpression: [
|
||||
[/[^\\"]+/, "string"],
|
||||
[/@escapes/, "string.escape"],
|
||||
[/\\./, "string.escape.invalid"],
|
||||
[/"/, "string", "@pop"],
|
||||
[/[^\\"]+/, 'string'],
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/\\./, 'string.escape.invalid'],
|
||||
[/"/, 'string', '@pop']
|
||||
],
|
||||
stringExpression: [
|
||||
[/\}/, { token: "delimiter", next: "@pop" }],
|
||||
[/"/, "string", "@stringInsideExpression"],
|
||||
{ include: "@terraform" },
|
||||
],
|
||||
},
|
||||
[/\}/, { token: 'delimiter', next: '@pop' }],
|
||||
[/"/, 'string', '@stringInsideExpression'],
|
||||
{ include: '@terraform' }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue