Skip to content

Commit

Permalink
Update Bicep grammar with recent additions (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Sep 16, 2023
1 parent c64e1be commit 94d11ab
Show file tree
Hide file tree
Showing 23 changed files with 1,932 additions and 197 deletions.
84 changes: 50 additions & 34 deletions lexers/embedded/bicep.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,79 @@
<filename>*.bicep</filename>
</config>
<rules>
<state name="root">
<state name="interp">
<rule pattern="'">
<token type="LiteralString"/>
<pop depth="1"/>
</rule>
<rule pattern="\\.">
<token type="LiteralString"/>
</rule>
<rule pattern="\$\{">
<token type="LiteralStringInterpol"/>
<push state="interp-inside"/>
</rule>
<rule pattern="\$">
<token type="LiteralString"/>
</rule>
<rule pattern="[^'\\$]+">
<token type="LiteralString"/>
</rule>
</state>
<state name="interp-inside">
<rule pattern="\}">
<token type="LiteralStringInterpol"/>
<pop depth="1"/>
</rule>
<rule>
<include state="root"/>
</rule>
</state>
<state name="commentsandwhitespace">
<rule pattern="//[^\n\r]+">
<token type="CommentSingle"/>
</rule>
<rule pattern="/\*.*?\*/">
<token type="CommentMultiline"/>
</rule>
<rule pattern="([&#39;]?\w+[&#39;]?)(:)">
<bygroups>
<token type="NameProperty"/>
<token type="Punctuation"/>
</bygroups>
</rule>
<rule pattern="\b(&#39;(resourceGroup|subscription|managementGroup|tenant)&#39;)\b">
<token type="KeywordNamespace"/>
<rule pattern="\s+">
<token type="TextWhitespace"/>
</rule>
<rule pattern="&#39;[\w\$\{\(\)\}\.]{1,}?&#39;">
<token type="LiteralStringInterpol"/>
</state>
<state name="root">
<rule>
<include state="commentsandwhitespace"/>
</rule>
<rule pattern="(&#39;&#39;&#39;|&#39;).*?(&#39;&#39;&#39;|&#39;)">
<rule pattern="'''.*?'''">
<token type="LiteralString"/>
</rule>
<rule pattern="\b(allowed|batchSize|description|maxLength|maxValue|metadata|minLength|minValue|secure)\b">
<token type="NameDecorator"/>
<rule pattern="'">
<token type="LiteralString"/>
<push state="interp"/>
</rule>
<rule pattern="\b(az|sys)\.">
<token type="NameNamespace"/>
<rule pattern="#[\w-]+\b">
<token type="CommentPreproc"/>
</rule>
<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">
<rule pattern="[\w_]+(?=\()">
<token type="NameFunction"/>
</rule>
<rule pattern="\b(bool)(\()">
<bygroups>
<token type="NameFunction"/>
<token type="Punctuation"/>
</bygroups>
</rule>
<rule pattern="\b(for|if|in)\b">
<token type="Keyword"/>
</rule>
<rule pattern="\b(module|output|param|resource|var)\b">
<rule pattern="\b(metadata|targetScope|resource|module|param|var|output|for|in|if|existing|import|as|type|with|using|func|assert)\b">
<token type="KeywordDeclaration"/>
</rule>
<rule pattern="\b(array|bool|int|object|string)\b">
<token type="KeywordType"/>
<rule pattern="\b(true|false|null)\b">
<token type="KeywordConstant"/>
</rule>
<rule pattern="(&gt;=|&gt;|&lt;=|&lt;|==|!=|=~|!~|::|&amp;&amp;|\?\?|!|-|%|\*|\/|\+)">
<token type="Operator"/>
</rule>
<rule pattern="[\(\)\[\]\.:\?{}@=]">
<rule pattern="(\(|\)|\[|\]|\.|:|\?|{|}|@|,|\||=&gt;|=)">
<token type="Punctuation"/>
</rule>
<rule pattern="[\w_-]+">
<token type="Text"/>
<rule pattern="[\w_]+">
<token type="NameVariable"/>
</rule>
<rule pattern="\s+">
<token type="TextWhitespace"/>
<rule pattern="[0-9]+">
<token type="LiteralNumberInteger"/>
</rule>
</state>
</rules>
Expand Down
16 changes: 8 additions & 8 deletions lexers/testdata/bicep/bicep-coalesce-operator.expected
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[
{"type":"KeywordDeclaration","value":"output"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"nonNullStr"},
{"type":"NameVariable","value":"nonNullStr"},
{"type":"TextWhitespace","value":" "},
{"type":"NameFunction","value":"string"},
{"type":"NameVariable","value":"string"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"myObject"},
{"type":"NameVariable","value":"myObject"},
{"type":"Punctuation","value":"."},
{"type":"Text","value":"isnull1"},
{"type":"NameVariable","value":"isnull1"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"??"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"myObject"},
{"type":"NameVariable","value":"myObject"},
{"type":"Punctuation","value":"."},
{"type":"NameFunction","value":"string"},
{"type":"NameVariable","value":"string"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"??"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"myObject"},
{"type":"NameVariable","value":"myObject"},
{"type":"Punctuation","value":"."},
{"type":"Text","value":"isnull2"}
{"type":"NameVariable","value":"isnull2"}
]
15 changes: 14 additions & 1 deletion lexers/testdata/bicep/bicep-comments.actual
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@ resource nic1 'Microsoft.Network/networkInterfaces@2020-06-01' = {
This Bicep file assumes the key vault already exists and
is in same subscription and resource group as the deployment.
*/
param existingKeyVaultName string
param existingKeyVaultName string

resource test 'Microsoft.AAD/domainServices@2021-03-01' = {
name: 'asdfsdf'
// this is a comment
properties: {/*comment*/
domainConfigurationType/*comment*/:/*comment*/'as//notacomment!d/* also not a comment */fsdf'// test!/*
/* multi
line
comment */ domainName: /*
asdf*/'test'
// comment
}
}
99 changes: 77 additions & 22 deletions lexers/testdata/bicep/bicep-comments.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{"type":"TextWhitespace","value":"\n"},
{"type":"KeywordDeclaration","value":"resource"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"nic1"},
{"type":"NameVariable","value":"nic1"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"'Microsoft.Network/networkInterfaces@2020-06-01'"},
{"type":"TextWhitespace","value":" "},
Expand All @@ -15,52 +15,107 @@
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Operator","value":"/*"},
{"type":"TextWhitespace","value":"\n "},
{"type":"Text","value":"This"},
{"type":"NameVariable","value":"This"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"Bicep"},
{"type":"NameVariable","value":"Bicep"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"file"},
{"type":"NameVariable","value":"file"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"assumes"},
{"type":"NameVariable","value":"assumes"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"the"},
{"type":"NameVariable","value":"the"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"key"},
{"type":"NameVariable","value":"key"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"vault"},
{"type":"NameVariable","value":"vault"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"already"},
{"type":"NameVariable","value":"already"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"exists"},
{"type":"NameVariable","value":"exists"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"and"},
{"type":"NameVariable","value":"and"},
{"type":"TextWhitespace","value":"\n "},
{"type":"Text","value":"is"},
{"type":"NameVariable","value":"is"},
{"type":"TextWhitespace","value":" "},
{"type":"Keyword","value":"in"},
{"type":"KeywordDeclaration","value":"in"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"same"},
{"type":"NameVariable","value":"same"},
{"type":"TextWhitespace","value":" "},
{"type":"NameFunction","value":"subscription"},
{"type":"NameVariable","value":"subscription"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"and"},
{"type":"NameVariable","value":"and"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordDeclaration","value":"resource"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"group"},
{"type":"NameVariable","value":"group"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"as"},
{"type":"KeywordDeclaration","value":"as"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"the"},
{"type":"NameVariable","value":"the"},
{"type":"TextWhitespace","value":" "},
{"type":"NameFunction","value":"deployment"},
{"type":"NameVariable","value":"deployment"},
{"type":"Punctuation","value":"."},
{"type":"TextWhitespace","value":"\n"},
{"type":"Operator","value":"*/"},
{"type":"TextWhitespace","value":"\n"},
{"type":"KeywordDeclaration","value":"param"},
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"existingKeyVaultName"},
{"type":"NameVariable","value":"existingKeyVaultName"},
{"type":"TextWhitespace","value":" "},
{"type":"NameFunction","value":"string"}
{"type":"NameVariable","value":"string"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"KeywordDeclaration","value":"resource"},
{"type":"TextWhitespace","value":" "},
{"type":"NameVariable","value":"test"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"'Microsoft.AAD/domainServices@2021-03-01'"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"name"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"'asdfsdf'"},
{"type":"TextWhitespace","value":"\n "},
{"type":"CommentSingle","value":"// this is a comment"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"properties"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"CommentMultiline","value":"/*comment*/"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"domainConfigurationType"},
{"type":"CommentMultiline","value":"/*comment*/"},
{"type":"Punctuation","value":":"},
{"type":"CommentMultiline","value":"/*comment*/"},
{"type":"LiteralString","value":"'as//notacomment!d/* also not a comment */fsdf'"},
{"type":"CommentSingle","value":"// test!/*"},
{"type":"TextWhitespace","value":"\n "},
{"type":"Operator","value":"/*"},
{"type":"TextWhitespace","value":" "},
{"type":"NameVariable","value":"multi"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"line"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"comment"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"*/"},
{"type":"TextWhitespace","value":" "},
{"type":"NameVariable","value":"domainName"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"/*"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameVariable","value":"asdf"},
{"type":"Operator","value":"*/"},
{"type":"LiteralString","value":"'test'"},
{"type":"TextWhitespace","value":"\n "},
{"type":"CommentSingle","value":"// comment"},
{"type":"TextWhitespace","value":"\n "},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Punctuation","value":"}"}
]
24 changes: 24 additions & 0 deletions lexers/testdata/bicep/bicep-directives.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var vmProperties = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: 123
storageUri: true
unknownProp: 'asdf'
}
}
evictionPolicy: 'Deallocate'
}
resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
name: 'vm'
location: 'West US'
#disable-next-line BCP036 BCP037
properties: vmProperties
}
#disable-next-line no-unused-params
param storageAccount1 string = 'testStorageAccount'
#disable-next-line no-unused-params
param storageAccount2 string = 'testStorageAccount'
#disable-next-line no-unused-params /* Test comment 1 */
param storageAccount3 string = 'testStorageAccount'
#disable-next-line no-unused-params // Test comment 2
param storageAccount5 string = 'testStorageAccount'
Loading

0 comments on commit 94d11ab

Please sign in to comment.