Skip to content

feat(lexer): add BicepLexer for Azure Bicep deployment files#3109

Open
mvanhorn wants to merge 1 commit into
pygments:masterfrom
mvanhorn:feat/bicep-lexer
Open

feat(lexer): add BicepLexer for Azure Bicep deployment files#3109
mvanhorn wants to merge 1 commit into
pygments:masterfrom
mvanhorn:feat/bicep-lexer

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

What

Adds a BicepLexer for Azure Bicep, the declarative deployment language for Azure resources, claiming *.bicep and *.bicepparam.

Closes #2938.

Coverage

  • 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, the sys namespace marker
  • Constants: true, false, null
  • Curated function namespace (the most-used sys / resource / string / file-loading functions get Name.Builtin). Bicep ships hundreds of functions across sys, 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 as Name.
  • Decorators (@description, @secure, etc.)
  • Single-quoted strings, triple-quoted multiline strings, and ${...} interpolation that pops into the root state for nested expressions
  • Single-line // and block /* */ comments
  • Multi-character operators (==, !=, <=, >=, &&, ||, ??, =>, .., ?., ::) tokenised before the single-char fallback

Resource 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: add BicepLexer class, append to __all__
  • pygments/lexers/_mapping.py: register between BibTeXLexer and BlitzBasicLexer (alphabetical) with filenames *.bicep, *.bicepparam
  • tests/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 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 check on a real .bicep file: decorators, keywords, types, strings, interpolation all render distinct

Reference

Closes #2938

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a lexer for Bicep

1 participant