Skip to content

Commit

Permalink
feat(grammars): add bicep (massCodeIO#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov authored Jan 10, 2023
1 parent b92e403 commit e461e51
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
18 changes: 18 additions & 0 deletions demo/db/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,24 @@
"id": "vH7mmfKH",
"createdAt": 1673326490808,
"updatedAt": 1673326641538
},
{
"isDeleted": false,
"isFavorites": false,
"folderId": "J7rNZi7X",
"tagsIds": [],
"description": null,
"name": "Bicep",
"content": [
{
"label": "Fragment 1",
"language": "bicep",
"value": "param rgLocation string = resourceGroup().location\nparam storages array = [\n {\n name: 'contoso'\n skuName: 'Standard_LRS'\n }\n {\n name: 'fabrikam'\n skuName: 'Premium_LRS'\n }\n]\n\nresource createStorages 'Microsoft.Storage/storageAccounts@2021-06-01' = [for storage in storages: {\n name: '${storage.name}obj${uniqueString(resourceGroup().id)}'\n location: rgLocation\n sku: {\n name: storage.skuName\n }\n kind: 'StorageV2'\n}]"
}
],
"id": "W9p-A0M9",
"createdAt": 1673328306847,
"updatedAt": 1673328471208
}
],
"tags": []
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This is a list of language that supports in massCode.
- AutoHotkey / AutoIt
- Bash
- BatchFile
- Bicep
- C and C++
- C#
- Cirru
Expand Down
143 changes: 143 additions & 0 deletions src/renderer/components/editor/grammars/bicep.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"scopeName": "source.bicep",
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"patterns": [{ "include": "#expression" }, { "include": "#comments" }],
"repository": {
"line-comment": {
"name": "comment.line.double-slash.bicep",
"match": "//.*(?=$)"
},
"keyword": {
"name": "keyword.control.declaration.bicep",
"match": "\\b(metadata|targetScope|resource|module|param|var|output|for|in|if|existing|import|as|type|with)\\b"
},
"object-literal": {
"begin": "{",
"end": "}",
"patterns": [
{ "include": "#object-property-key" },
{ "include": "#expression" },
{ "include": "#comments" }
],
"name": "meta.object-literal.bicep"
},
"string-literal-subst": {
"begin": "(?<!\\\\)(\\${)",
"endCaptures": {
"1": { "name": "punctuation.definition.template-expression.end.bicep" }
},
"end": "(})",
"patterns": [{ "include": "#expression" }, { "include": "#comments" }],
"name": "meta.string-literal-subst.bicep",
"beginCaptures": {
"1": {
"name": "punctuation.definition.template-expression.begin.bicep"
}
}
},
"array-literal": {
"begin": "\\[(?!(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\bfor\\b)",
"end": "]",
"patterns": [{ "include": "#expression" }, { "include": "#comments" }],
"name": "meta.array-literal.bicep"
},
"object-property-key": {
"name": "variable.other.property.bicep",
"match": "\\b[_$[:alpha:]][_$[:alnum:]]*\\b(?=(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*:)"
},
"string-verbatim": {
"begin": "'''",
"end": "'''",
"patterns": [],
"name": "string.quoted.multi.bicep"
},
"lambda-start": {
"begin": "(\\((?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\b[_$[:alpha:]][_$[:alnum:]]*\\b(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*(,(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\b[_$[:alpha:]][_$[:alnum:]]*\\b(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*)*\\)|\\((?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\)|(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\b[_$[:alpha:]][_$[:alnum:]]*\\b(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*)(?=(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*=>)",
"end": "(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*=>",
"name": "meta.lambda-start.bicep",
"beginCaptures": {
"1": {
"name": "meta.undefined.bicep",
"patterns": [{ "include": "#identifier" }, { "include": "#comments" }]
}
}
},
"function-call": {
"begin": "(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\(",
"end": "\\)",
"patterns": [{ "include": "#expression" }, { "include": "#comments" }],
"name": "meta.function-call.bicep",
"beginCaptures": { "1": { "name": "entity.name.function.bicep" } }
},
"escape-character": {
"name": "constant.character.escape.bicep",
"match": "\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\${)"
},
"identifier": {
"name": "variable.other.readwrite.bicep",
"match": "\\b[_$[:alpha:]][_$[:alnum:]]*\\b(?!(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*\\()"
},
"string-literal": {
"begin": "'(?!'')",
"end": "'",
"patterns": [
{ "include": "#escape-character" },
{ "include": "#string-literal-subst" }
],
"name": "string.quoted.single.bicep"
},
"directive-variable": {
"name": "keyword.control.declaration.bicep",
"match": "\\b[_a-zA-Z-0-9]+\\b"
},
"directive": {
"begin": "#\\b[_a-zA-Z-0-9]+\\b",
"end": "$",
"patterns": [
{ "include": "#directive-variable" },
{ "include": "#comments" }
],
"name": "meta.directive.bicep"
},
"decorator": {
"begin": "@(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*(?=\\b[_$[:alpha:]][_$[:alnum:]]*\\b)",
"end": "",
"patterns": [{ "include": "#expression" }, { "include": "#comments" }],
"name": "meta.decorator.bicep"
},
"block-comment": {
"name": "comment.block.bicep",
"begin": "/\\*",
"end": "\\*/"
},
"comments": {
"patterns": [
{ "include": "#line-comment" },
{ "include": "#block-comment" }
]
},
"numeric-literal": { "name": "constant.numeric.bicep", "match": "[0-9]+" },
"expression": {
"patterns": [
{ "include": "#string-literal" },
{ "include": "#string-verbatim" },
{ "include": "#numeric-literal" },
{ "include": "#named-literal" },
{ "include": "#object-literal" },
{ "include": "#array-literal" },
{ "include": "#keyword" },
{ "include": "#identifier" },
{ "include": "#function-call" },
{ "include": "#decorator" },
{ "include": "#lambda-start" },
{ "include": "#directive" }
]
},
"named-literal": {
"name": "constant.language.bicep",
"match": "\\b(true|false|null)\\b"
}
},
"name": "Bicep",
"fileTypes": [".bicep"]
}
6 changes: 6 additions & 0 deletions src/renderer/components/editor/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export const languages: LanguageOption[] = [
grammar: () => import('./grammars/batchfile.tmLanguage.json'),
scopeName: 'source.batchfile'
},
{
name: 'Bicep',
value: 'bicep',
grammar: () => import('./grammars/bicep.tmLanguage.json'),
scopeName: 'source.bicep'
},
{
name: 'C and C++',
value: 'c_cpp',
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/renderer/editor/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Language =
| 'assembly_x86'
| 'autohotkey'
| 'batchfile'
| 'bicep'
| 'c_cpp'
| 'c9search'
| 'cirru'
Expand Down

0 comments on commit e461e51

Please sign in to comment.