Skip to content

Commit 748bb9a

Browse files
Bicep: Resolved TODO + improvements (#3028)
1 parent b0365e7 commit 748bb9a

File tree

9 files changed

+282
-46
lines changed

9 files changed

+282
-46
lines changed

components/prism-bicep.js

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,64 @@ Prism.languages.bicep = {
1414
greedy: true
1515
}
1616
],
17-
'string': {
18-
// this doesn't handle string interpolalation or multiline strings as yet
19-
pattern: /'(?:\\.|[^'\\\r\n])*'/,
20-
greedy: true
17+
18+
'property': [
19+
{
20+
pattern: /([\r\n][ \t]*)[a-z_]\w*(?=[ \t]*:)/i,
21+
lookbehind: true
22+
},
23+
{
24+
pattern: /([\r\n][ \t]*)'(?:\\.|\$(?!\{)|[^'\\\r\n$])*'(?=[ \t]*:)/,
25+
lookbehind: true,
26+
greedy: true
27+
}
28+
],
29+
'string': [
30+
{
31+
pattern: /'''[^'][\s\S]*?'''/,
32+
greedy: true
33+
},
34+
{
35+
pattern: /(^|[^\\'])'(?:\\.|\$(?!\{)|[^'\\\r\n$])*'/,
36+
lookbehind: true,
37+
greedy: true,
38+
}
39+
],
40+
'interpolated-string': {
41+
pattern: /(^|[^\\'])'(?:\\.|\$(?:(?!\{)|\{[^{}\r\n]*\})|[^'\\\r\n$])*'/,
42+
lookbehind: true,
43+
greedy: true,
44+
inside: {
45+
'interpolation': {
46+
pattern: /\$\{[^{}\r\n]*\}/,
47+
inside: {
48+
'expression': {
49+
pattern: /(^\$\{)[\s\S]+(?=\}$)/,
50+
lookbehind: true
51+
},
52+
'punctuation': /^\$\{|\}$/,
53+
}
54+
},
55+
'string': /[\s\S]+/
56+
}
2157
},
22-
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?/i,
58+
59+
'datatype': {
60+
pattern: /(\b(?:output|param)\b[ \t]+\w+[ \t]+)\w+\b/,
61+
lookbehind: true,
62+
alias: 'class-name'
63+
},
64+
2365
'boolean': /\b(?:true|false)\b/,
24-
'keyword': /\b(?:targetScope|resource|module|param|var|output|for|in|if|existing|null)\b/, // https://github.com/Azure/bicep/blob/114a3251b4e6e30082a58729f19a8cc4e374ffa6/src/textmate/bicep.tmlanguage#L184
25-
'function': /\b(?:array|concat|contains|createArray|empty|first|intersection|last|length|max|min|range|skip|take|union)(?:\$|\b)/, // https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-array
66+
// https://github.com/Azure/bicep/blob/114a3251b4e6e30082a58729f19a8cc4e374ffa6/src/textmate/bicep.tmlanguage#L184
67+
'keyword': /\b(?:targetScope|resource|module|param|var|output|for|in|if|existing|null)\b/,
68+
69+
'decorator': /@\w+\b/,
70+
'function': /\b[a-z_]\w*(?=[ \t]*\()/i,
71+
72+
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?/i,
2673
'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/,
2774
'punctuation': /[{}[\];(),.:]/,
28-
'decorator': /@\w+\b/
2975
};
76+
77+
Prism.languages.bicep['interpolated-string'].inside['interpolation'].inside['expression'].inside = Prism.languages.bicep;

components/prism-bicep.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// this is a comment
2+
3+
/* this
4+
is a
5+
multi line comment */
6+
7+
/* so is
8+
this */
9+
10+
----------------------------------------------------
11+
12+
[
13+
["comment", "// this is a comment"],
14+
15+
["comment", "/* this\r\nis a\r\nmulti line comment */"],
16+
17+
["comment", "/* so is\r\nthis */"]
18+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
param myString string
2+
param myInt int
3+
param myBool bool
4+
param myObject object
5+
param myArray array
6+
7+
output myHardcodedOutput int = 42
8+
output myLoopyOutput array = [for myItem in myArray: {
9+
myProperty: myItem.myOtherProperty
10+
}]
11+
12+
----------------------------------------------------
13+
14+
[
15+
["keyword", "param"], " myString ", ["datatype", "string"],
16+
["keyword", "param"], " myInt ", ["datatype", "int"],
17+
["keyword", "param"], " myBool ", ["datatype", "bool"],
18+
["keyword", "param"], " myObject ", ["datatype", "object"],
19+
["keyword", "param"], " myArray ", ["datatype", "array"],
20+
21+
["keyword", "output"],
22+
" myHardcodedOutput ",
23+
["datatype", "int"],
24+
["operator", "="],
25+
["number", "42"],
26+
27+
["keyword", "output"],
28+
" myLoopyOutput ",
29+
["datatype", "array"],
30+
["operator", "="],
31+
["punctuation", "["],
32+
["keyword", "for"],
33+
" myItem ",
34+
["keyword", "in"],
35+
" myArray",
36+
["operator", ":"],
37+
["punctuation", "{"],
38+
39+
["property", "myProperty"],
40+
["operator", ":"],
41+
" myItem",
42+
["punctuation", "."],
43+
"myOtherProperty\r\n",
44+
45+
["punctuation", "}"],
46+
["punctuation", "]"]
47+
]

tests/languages/bicep/decorator_feature.test

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,54 @@ param demoPassword string
66
])
77
param demoEnum string
88

9+
@minLength(3)
10+
@maxLength(24)
11+
@description('Name of the storage account')
12+
param storageAccountName string = concat(uniqueString(resourceGroup().id), 'sa')
13+
914
----------------------------------------------------
1015

1116
[
1217
["decorator", "@secure"], ["punctuation", "("], ["punctuation", ")"],
13-
["keyword", "param"], " demoPassword string\r\n",
18+
["keyword", "param"], " demoPassword ", ["datatype", "string"],
1419
["decorator", "@allowed"], ["punctuation", "("], ["punctuation", "["],
1520
["string", "'one'"],
1621
["string", "'two'"],
1722
["punctuation", "]"], ["punctuation", ")"],
18-
["keyword", "param"], " demoEnum string"
23+
["keyword", "param"], " demoEnum ", ["datatype", "string"],
24+
25+
["decorator", "@minLength"],
26+
["punctuation", "("],
27+
["number", "3"],
28+
["punctuation", ")"],
29+
30+
["decorator", "@maxLength"],
31+
["punctuation", "("],
32+
["number", "24"],
33+
["punctuation", ")"],
34+
35+
["decorator", "@description"],
36+
["punctuation", "("],
37+
["string", "'Name of the storage account'"],
38+
["punctuation", ")"],
39+
40+
["keyword", "param"],
41+
" storageAccountName ",
42+
["datatype", "string"],
43+
["operator", "="],
44+
["function", "concat"],
45+
["punctuation", "("],
46+
["function", "uniqueString"],
47+
["punctuation", "("],
48+
["function", "resourceGroup"],
49+
["punctuation", "("],
50+
["punctuation", ")"],
51+
["punctuation", "."],
52+
"id",
53+
["punctuation", ")"],
54+
["punctuation", ","],
55+
["string", "'sa'"],
56+
["punctuation", ")"]
1957
]
2058

2159
----------------------------------------------------

tests/languages/bicep/function_feature.test

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,60 @@
1-
array
2-
concat
3-
contains
4-
createArray
5-
empty
6-
first
7-
intersection
8-
last
9-
length
10-
max
11-
min
12-
range
13-
skip
14-
take
15-
union
1+
param location string = resourceGroup().location
2+
var hostingPlanName = 'hostingplan${uniqueString(resourceGroup().id)}'
3+
4+
array(parameters('stringToConvert'))
5+
createArray(1, 2, 3)
166

177
----------------------------------------------------
188

199
[
10+
["keyword", "param"],
11+
" location ",
12+
["datatype", "string"],
13+
["operator", "="],
14+
["function", "resourceGroup"],
15+
["punctuation", "("],
16+
["punctuation", ")"],
17+
["punctuation", "."],
18+
"location\r\n",
19+
20+
["keyword", "var"],
21+
" hostingPlanName ",
22+
["operator", "="],
23+
["interpolated-string", [
24+
["string", "'hostingplan"],
25+
["interpolation", [
26+
["punctuation", "${"],
27+
["expression", [
28+
["function", "uniqueString"],
29+
["punctuation", "("],
30+
["function", "resourceGroup"],
31+
["punctuation", "("],
32+
["punctuation", ")"],
33+
["punctuation", "."],
34+
"id",
35+
["punctuation", ")"]
36+
]],
37+
["punctuation", "}"]
38+
]],
39+
["string", "'"]
40+
]],
41+
2042
["function", "array"],
21-
["function", "concat"],
22-
["function", "contains"],
43+
["punctuation", "("],
44+
["function", "parameters"],
45+
["punctuation", "("],
46+
["string", "'stringToConvert'"],
47+
["punctuation", ")"],
48+
["punctuation", ")"],
49+
2350
["function", "createArray"],
24-
["function", "empty"],
25-
["function", "first"],
26-
["function", "intersection"],
27-
["function", "last"],
28-
["function", "length"],
29-
["function", "max"],
30-
["function", "min"],
31-
["function", "range"],
32-
["function", "skip"],
33-
["function", "take"],
34-
["function", "union"]
51+
["punctuation", "("],
52+
["number", "1"],
53+
["punctuation", ","],
54+
["number", "2"],
55+
["punctuation", ","],
56+
["number", "3"],
57+
["punctuation", ")"]
3558
]
3659

3760
----------------------------------------------------

tests/languages/bicep/keyword_feature.test

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ null
3131
["punctuation", ")"],
3232
["punctuation", "{"],
3333

34-
"\r\n name",
34+
["property", "name"],
3535
["operator", ":"],
3636
" logAnalyticsWsName\r\n",
3737

@@ -43,22 +43,24 @@ null
4343
["operator", "="],
4444
["punctuation", "{"],
4545

46-
"\r\n name",
46+
["property", "name"],
4747
["operator", ":"],
4848
["string", "'cosmosDbDeploy'"],
4949

5050
["punctuation", "}"],
5151

5252
["keyword", "param"],
53-
" env string\r\n",
53+
" env ",
54+
["datatype", "string"],
5455

5556
["keyword", "var"],
5657
" oneNumber ",
5758
["operator", "="],
5859
["number", "123"],
5960

6061
["keyword", "output"],
61-
" databaseName string ",
62+
" databaseName ",
63+
["datatype", "string"],
6264
["operator", "="],
6365
" cosmosdbDatabaseName\r\n",
6466

@@ -69,7 +71,7 @@ null
6971
["operator", ":"],
7072
["punctuation", "{"],
7173

72-
"\r\n\tipAddressOrRange",
74+
["property", "ipAddressOrRange"],
7375
["operator", ":"],
7476
" item\r\n",
7577

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy