Skip to content

Commit 94d11ab

Browse files
Update Bicep grammar with recent additions (#850)
1 parent c64e1be commit 94d11ab

23 files changed

+1932
-197
lines changed

lexers/embedded/bicep.xml

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,79 @@
55
<filename>*.bicep</filename>
66
</config>
77
<rules>
8-
<state name="root">
8+
<state name="interp">
9+
<rule pattern="'">
10+
<token type="LiteralString"/>
11+
<pop depth="1"/>
12+
</rule>
13+
<rule pattern="\\.">
14+
<token type="LiteralString"/>
15+
</rule>
16+
<rule pattern="\$\{">
17+
<token type="LiteralStringInterpol"/>
18+
<push state="interp-inside"/>
19+
</rule>
20+
<rule pattern="\$">
21+
<token type="LiteralString"/>
22+
</rule>
23+
<rule pattern="[^'\\$]+">
24+
<token type="LiteralString"/>
25+
</rule>
26+
</state>
27+
<state name="interp-inside">
28+
<rule pattern="\}">
29+
<token type="LiteralStringInterpol"/>
30+
<pop depth="1"/>
31+
</rule>
32+
<rule>
33+
<include state="root"/>
34+
</rule>
35+
</state>
36+
<state name="commentsandwhitespace">
937
<rule pattern="//[^\n\r]+">
1038
<token type="CommentSingle"/>
1139
</rule>
1240
<rule pattern="/\*.*?\*/">
1341
<token type="CommentMultiline"/>
1442
</rule>
15-
<rule pattern="([&#39;]?\w+[&#39;]?)(:)">
16-
<bygroups>
17-
<token type="NameProperty"/>
18-
<token type="Punctuation"/>
19-
</bygroups>
20-
</rule>
21-
<rule pattern="\b(&#39;(resourceGroup|subscription|managementGroup|tenant)&#39;)\b">
22-
<token type="KeywordNamespace"/>
43+
<rule pattern="\s+">
44+
<token type="TextWhitespace"/>
2345
</rule>
24-
<rule pattern="&#39;[\w\$\{\(\)\}\.]{1,}?&#39;">
25-
<token type="LiteralStringInterpol"/>
46+
</state>
47+
<state name="root">
48+
<rule>
49+
<include state="commentsandwhitespace"/>
2650
</rule>
27-
<rule pattern="(&#39;&#39;&#39;|&#39;).*?(&#39;&#39;&#39;|&#39;)">
51+
<rule pattern="'''.*?'''">
2852
<token type="LiteralString"/>
2953
</rule>
30-
<rule pattern="\b(allowed|batchSize|description|maxLength|maxValue|metadata|minLength|minValue|secure)\b">
31-
<token type="NameDecorator"/>
54+
<rule pattern="'">
55+
<token type="LiteralString"/>
56+
<push state="interp"/>
3257
</rule>
33-
<rule pattern="\b(az|sys)\.">
34-
<token type="NameNamespace"/>
58+
<rule pattern="#[\w-]+\b">
59+
<token type="CommentPreproc"/>
3560
</rule>
36-
<rule pattern="\b(any|array|concat|contains|empty|first|intersection|items|last|length|min|max|range|skip|take|union|dateTimeAdd|utcNow|deployment|environment|loadFileAsBase64|loadTextContent|int|json|extensionResourceId|getSecret|list|listKeys|listKeyValue|listAccountSas|listSecrets|pickZones|reference|resourceId|subscriptionResourceId|tenantResourceId|managementGroup|resourceGroup|subscription|tenant|base64|base64ToJson|base64ToString|dataUri|dataUriToString|endsWith|format|guid|indexOf|lastIndexOf|length|newGuid|padLeft|replace|split|startsWith|string|substring|toLower|toUpper|trim|uniqueString|uri|uriComponent|uriComponentToString)\b">
61+
<rule pattern="[\w_]+(?=\()">
3762
<token type="NameFunction"/>
3863
</rule>
39-
<rule pattern="\b(bool)(\()">
40-
<bygroups>
41-
<token type="NameFunction"/>
42-
<token type="Punctuation"/>
43-
</bygroups>
44-
</rule>
45-
<rule pattern="\b(for|if|in)\b">
46-
<token type="Keyword"/>
47-
</rule>
48-
<rule pattern="\b(module|output|param|resource|var)\b">
64+
<rule pattern="\b(metadata|targetScope|resource|module|param|var|output|for|in|if|existing|import|as|type|with|using|func|assert)\b">
4965
<token type="KeywordDeclaration"/>
5066
</rule>
51-
<rule pattern="\b(array|bool|int|object|string)\b">
52-
<token type="KeywordType"/>
67+
<rule pattern="\b(true|false|null)\b">
68+
<token type="KeywordConstant"/>
5369
</rule>
5470
<rule pattern="(&gt;=|&gt;|&lt;=|&lt;|==|!=|=~|!~|::|&amp;&amp;|\?\?|!|-|%|\*|\/|\+)">
5571
<token type="Operator"/>
5672
</rule>
57-
<rule pattern="[\(\)\[\]\.:\?{}@=]">
73+
<rule pattern="(\(|\)|\[|\]|\.|:|\?|{|}|@|,|\||=&gt;|=)">
5874
<token type="Punctuation"/>
5975
</rule>
60-
<rule pattern="[\w_-]+">
61-
<token type="Text"/>
76+
<rule pattern="[\w_]+">
77+
<token type="NameVariable"/>
6278
</rule>
63-
<rule pattern="\s+">
64-
<token type="TextWhitespace"/>
79+
<rule pattern="[0-9]+">
80+
<token type="LiteralNumberInteger"/>
6581
</rule>
6682
</state>
6783
</rules>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
[
22
{"type":"KeywordDeclaration","value":"output"},
33
{"type":"TextWhitespace","value":" "},
4-
{"type":"Text","value":"nonNullStr"},
4+
{"type":"NameVariable","value":"nonNullStr"},
55
{"type":"TextWhitespace","value":" "},
6-
{"type":"NameFunction","value":"string"},
6+
{"type":"NameVariable","value":"string"},
77
{"type":"TextWhitespace","value":" "},
88
{"type":"Punctuation","value":"="},
99
{"type":"TextWhitespace","value":" "},
10-
{"type":"Text","value":"myObject"},
10+
{"type":"NameVariable","value":"myObject"},
1111
{"type":"Punctuation","value":"."},
12-
{"type":"Text","value":"isnull1"},
12+
{"type":"NameVariable","value":"isnull1"},
1313
{"type":"TextWhitespace","value":" "},
1414
{"type":"Operator","value":"??"},
1515
{"type":"TextWhitespace","value":" "},
16-
{"type":"Text","value":"myObject"},
16+
{"type":"NameVariable","value":"myObject"},
1717
{"type":"Punctuation","value":"."},
18-
{"type":"NameFunction","value":"string"},
18+
{"type":"NameVariable","value":"string"},
1919
{"type":"TextWhitespace","value":" "},
2020
{"type":"Operator","value":"??"},
2121
{"type":"TextWhitespace","value":" "},
22-
{"type":"Text","value":"myObject"},
22+
{"type":"NameVariable","value":"myObject"},
2323
{"type":"Punctuation","value":"."},
24-
{"type":"Text","value":"isnull2"}
24+
{"type":"NameVariable","value":"isnull2"}
2525
]

lexers/testdata/bicep/bicep-comments.actual

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,17 @@ resource nic1 'Microsoft.Network/networkInterfaces@2020-06-01' = {
66
This Bicep file assumes the key vault already exists and
77
is in same subscription and resource group as the deployment.
88
*/
9-
param existingKeyVaultName string
9+
param existingKeyVaultName string
10+
11+
resource test 'Microsoft.AAD/domainServices@2021-03-01' = {
12+
name: 'asdfsdf'
13+
// this is a comment
14+
properties: {/*comment*/
15+
domainConfigurationType/*comment*/:/*comment*/'as//notacomment!d/* also not a comment */fsdf'// test!/*
16+
/* multi
17+
line
18+
comment */ domainName: /*
19+
asdf*/'test'
20+
// comment
21+
}
22+
}

lexers/testdata/bicep/bicep-comments.expected

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{"type":"TextWhitespace","value":"\n"},
44
{"type":"KeywordDeclaration","value":"resource"},
55
{"type":"TextWhitespace","value":" "},
6-
{"type":"Text","value":"nic1"},
6+
{"type":"NameVariable","value":"nic1"},
77
{"type":"TextWhitespace","value":" "},
88
{"type":"LiteralString","value":"'Microsoft.Network/networkInterfaces@2020-06-01'"},
99
{"type":"TextWhitespace","value":" "},
@@ -15,52 +15,107 @@
1515
{"type":"TextWhitespace","value":"\n\n"},
1616
{"type":"Operator","value":"/*"},
1717
{"type":"TextWhitespace","value":"\n "},
18-
{"type":"Text","value":"This"},
18+
{"type":"NameVariable","value":"This"},
1919
{"type":"TextWhitespace","value":" "},
20-
{"type":"Text","value":"Bicep"},
20+
{"type":"NameVariable","value":"Bicep"},
2121
{"type":"TextWhitespace","value":" "},
22-
{"type":"Text","value":"file"},
22+
{"type":"NameVariable","value":"file"},
2323
{"type":"TextWhitespace","value":" "},
24-
{"type":"Text","value":"assumes"},
24+
{"type":"NameVariable","value":"assumes"},
2525
{"type":"TextWhitespace","value":" "},
26-
{"type":"Text","value":"the"},
26+
{"type":"NameVariable","value":"the"},
2727
{"type":"TextWhitespace","value":" "},
28-
{"type":"Text","value":"key"},
28+
{"type":"NameVariable","value":"key"},
2929
{"type":"TextWhitespace","value":" "},
30-
{"type":"Text","value":"vault"},
30+
{"type":"NameVariable","value":"vault"},
3131
{"type":"TextWhitespace","value":" "},
32-
{"type":"Text","value":"already"},
32+
{"type":"NameVariable","value":"already"},
3333
{"type":"TextWhitespace","value":" "},
34-
{"type":"Text","value":"exists"},
34+
{"type":"NameVariable","value":"exists"},
3535
{"type":"TextWhitespace","value":" "},
36-
{"type":"Text","value":"and"},
36+
{"type":"NameVariable","value":"and"},
3737
{"type":"TextWhitespace","value":"\n "},
38-
{"type":"Text","value":"is"},
38+
{"type":"NameVariable","value":"is"},
3939
{"type":"TextWhitespace","value":" "},
40-
{"type":"Keyword","value":"in"},
40+
{"type":"KeywordDeclaration","value":"in"},
4141
{"type":"TextWhitespace","value":" "},
42-
{"type":"Text","value":"same"},
42+
{"type":"NameVariable","value":"same"},
4343
{"type":"TextWhitespace","value":" "},
44-
{"type":"NameFunction","value":"subscription"},
44+
{"type":"NameVariable","value":"subscription"},
4545
{"type":"TextWhitespace","value":" "},
46-
{"type":"Text","value":"and"},
46+
{"type":"NameVariable","value":"and"},
4747
{"type":"TextWhitespace","value":" "},
4848
{"type":"KeywordDeclaration","value":"resource"},
4949
{"type":"TextWhitespace","value":" "},
50-
{"type":"Text","value":"group"},
50+
{"type":"NameVariable","value":"group"},
5151
{"type":"TextWhitespace","value":" "},
52-
{"type":"Text","value":"as"},
52+
{"type":"KeywordDeclaration","value":"as"},
5353
{"type":"TextWhitespace","value":" "},
54-
{"type":"Text","value":"the"},
54+
{"type":"NameVariable","value":"the"},
5555
{"type":"TextWhitespace","value":" "},
56-
{"type":"NameFunction","value":"deployment"},
56+
{"type":"NameVariable","value":"deployment"},
5757
{"type":"Punctuation","value":"."},
5858
{"type":"TextWhitespace","value":"\n"},
5959
{"type":"Operator","value":"*/"},
6060
{"type":"TextWhitespace","value":"\n"},
6161
{"type":"KeywordDeclaration","value":"param"},
6262
{"type":"TextWhitespace","value":" "},
63-
{"type":"Text","value":"existingKeyVaultName"},
63+
{"type":"NameVariable","value":"existingKeyVaultName"},
6464
{"type":"TextWhitespace","value":" "},
65-
{"type":"NameFunction","value":"string"}
65+
{"type":"NameVariable","value":"string"},
66+
{"type":"TextWhitespace","value":"\n\n"},
67+
{"type":"KeywordDeclaration","value":"resource"},
68+
{"type":"TextWhitespace","value":" "},
69+
{"type":"NameVariable","value":"test"},
70+
{"type":"TextWhitespace","value":" "},
71+
{"type":"LiteralString","value":"'Microsoft.AAD/domainServices@2021-03-01'"},
72+
{"type":"TextWhitespace","value":" "},
73+
{"type":"Punctuation","value":"="},
74+
{"type":"TextWhitespace","value":" "},
75+
{"type":"Punctuation","value":"{"},
76+
{"type":"TextWhitespace","value":"\n "},
77+
{"type":"NameVariable","value":"name"},
78+
{"type":"Punctuation","value":":"},
79+
{"type":"TextWhitespace","value":" "},
80+
{"type":"LiteralString","value":"'asdfsdf'"},
81+
{"type":"TextWhitespace","value":"\n "},
82+
{"type":"CommentSingle","value":"// this is a comment"},
83+
{"type":"TextWhitespace","value":"\n "},
84+
{"type":"NameVariable","value":"properties"},
85+
{"type":"Punctuation","value":":"},
86+
{"type":"TextWhitespace","value":" "},
87+
{"type":"Punctuation","value":"{"},
88+
{"type":"CommentMultiline","value":"/*comment*/"},
89+
{"type":"TextWhitespace","value":"\n "},
90+
{"type":"NameVariable","value":"domainConfigurationType"},
91+
{"type":"CommentMultiline","value":"/*comment*/"},
92+
{"type":"Punctuation","value":":"},
93+
{"type":"CommentMultiline","value":"/*comment*/"},
94+
{"type":"LiteralString","value":"'as//notacomment!d/* also not a comment */fsdf'"},
95+
{"type":"CommentSingle","value":"// test!/*"},
96+
{"type":"TextWhitespace","value":"\n "},
97+
{"type":"Operator","value":"/*"},
98+
{"type":"TextWhitespace","value":" "},
99+
{"type":"NameVariable","value":"multi"},
100+
{"type":"TextWhitespace","value":"\n "},
101+
{"type":"NameVariable","value":"line"},
102+
{"type":"TextWhitespace","value":"\n "},
103+
{"type":"NameVariable","value":"comment"},
104+
{"type":"TextWhitespace","value":" "},
105+
{"type":"Operator","value":"*/"},
106+
{"type":"TextWhitespace","value":" "},
107+
{"type":"NameVariable","value":"domainName"},
108+
{"type":"Punctuation","value":":"},
109+
{"type":"TextWhitespace","value":" "},
110+
{"type":"Operator","value":"/*"},
111+
{"type":"TextWhitespace","value":"\n "},
112+
{"type":"NameVariable","value":"asdf"},
113+
{"type":"Operator","value":"*/"},
114+
{"type":"LiteralString","value":"'test'"},
115+
{"type":"TextWhitespace","value":"\n "},
116+
{"type":"CommentSingle","value":"// comment"},
117+
{"type":"TextWhitespace","value":"\n "},
118+
{"type":"Punctuation","value":"}"},
119+
{"type":"TextWhitespace","value":"\n"},
120+
{"type":"Punctuation","value":"}"}
66121
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var vmProperties = {
2+
diagnosticsProfile: {
3+
bootDiagnostics: {
4+
enabled: 123
5+
storageUri: true
6+
unknownProp: 'asdf'
7+
}
8+
}
9+
evictionPolicy: 'Deallocate'
10+
}
11+
resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
12+
name: 'vm'
13+
location: 'West US'
14+
#disable-next-line BCP036 BCP037
15+
properties: vmProperties
16+
}
17+
#disable-next-line no-unused-params
18+
param storageAccount1 string = 'testStorageAccount'
19+
#disable-next-line no-unused-params
20+
param storageAccount2 string = 'testStorageAccount'
21+
#disable-next-line no-unused-params /* Test comment 1 */
22+
param storageAccount3 string = 'testStorageAccount'
23+
#disable-next-line no-unused-params // Test comment 2
24+
param storageAccount5 string = 'testStorageAccount'

0 commit comments

Comments
 (0)