feat(lexer): add BicepLexer for Azure Bicep deployment files#3109
Open
mvanhorn wants to merge 1 commit into
Open
feat(lexer): add BicepLexer for Azure Bicep deployment files#3109mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
Closes pygments#2938. Bicep is a domain-specific language for declarative deployment of Azure resources. Adds a RegexLexer covering the syntax users actually write day to day: - Top-level declaration keywords (`param`, `var`, `resource`, `module`, `output`, `targetScope`, `type`, `func`, `metadata`, `extension`/`provider`, `import`, `extends`, `using`). - Statement keywords: `if`, `else`, `for`, `in`. - Built-in types: `string`, `int`, `bool`, `array`, `object`, the `secure*` variants, and the `sys` namespace marker. - Constants: `true`, `false`, `null`. - Curated function namespace -- the most-used `sys` / resource / string / file-loading functions get marked `Name.Builtin`. Bicep ships hundreds of functions; the curated list trades long-tail coverage for predictability so we don't pretend to know every function. Anything not on the list still highlights as Name. - Decorators (`@description`, `@secure`, etc.). - Single-quoted strings, triple-quoted multiline strings, and `${...}` interpolation that pops back into the root rule for nested expressions. - Single-line `//` and block `/* */` comments. - Resource API-version literals (e.g. `'Microsoft.Storage/storageAccounts@2023-01-01'`) work via the ordinary single-quoted string path -- no special case needed. - Multi-character operators (`==`, `!=`, `<=`, `>=`, `&&`, `||`, `??`, `=>`, `..`, `?.`, `::`) tokenised before the single-char fallback so they don't mis-tokenise. Files: - `pygments/lexers/configs.py`: add `BicepLexer` class and append to `__all__`. - `pygments/lexers/_mapping.py`: register `BicepLexer` between BibTeXLexer and BlitzBasicLexer (alphabetical), claiming `*.bicep` and `*.bicepparam` filenames. - `tests/snippets/bicep/test_basic.txt`: golden snippet test covering decorators, declarations, types, the curated builtin function (`resourceGroup`), single-line + block comments, resource declaration with API-version literal, string interpolation, and an output binding. Test plan: pytest tests/snippets/bicep/ -> 1 passed pytest tests/snippets/terraform/ -> 10 passed (untouched) pytest tests/test_basic_api.py -> 2445 passed Manual visual on a real .bicep file looks correct (decorators, keywords, types, strings, interpolation all distinct)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
BicepLexerfor Azure Bicep, the declarative deployment language for Azure resources, claiming*.bicepand*.bicepparam.Closes #2938.
Coverage
param,var,resource,module,output,targetScope,type,func,metadata,extension/provider,import,extends,usingif,else,for,instring,int,bool,array,object, thesecure*variants, thesysnamespace markertrue,false,nullName.Builtin). Bicep ships hundreds of functions acrosssys,az, and resource-specific namespaces; the curated list trades long-tail coverage for predictability rather than pretending to know every function. Anything not on the list still highlights asName.@description,@secure, etc.)${...}interpolation that pops into the root state for nested expressions//and block/* */comments==,!=,<=,>=,&&,||,??,=>,..,?.,::) tokenised before the single-char fallbackResource API-version literals (e.g.
'Microsoft.Storage/storageAccounts@2023-01-01') work via the ordinary single-quoted string path; no special case needed.Files
pygments/lexers/configs.py: addBicepLexerclass, append to__all__pygments/lexers/_mapping.py: register betweenBibTeXLexerandBlitzBasicLexer(alphabetical) with filenames*.bicep,*.bicepparamtests/snippets/bicep/test_basic.txt: golden snippet test covering decorators, declarations, types, a curated builtin function (resourceGroup), single-line + block comments, a resource declaration with API-version literal, string interpolation, and an output bindingTest plan
pytest tests/snippets/bicep/-> 1 passedpytest tests/snippets/terraform/-> 10 passed (untouched)pytest tests/test_basic_api.py-> 2445 passed.bicepfile: decorators, keywords, types, strings, interpolation all render distinctReference
Closes #2938