Metadata-Version: 2.3
Name: pygments-cedar
Version: 2026.5.13.post0
Summary: Pygments lexer for the Cedar policy language
Requires-Dist: pygments>=2.0
Requires-Python: >=3.13
Description-Content-Type: text/markdown

# pygments-cedar

A [Pygments](https://pygments.org/) lexer plugin for the [Cedar](https://www.cedarpolicy.com/) policy language by AWS.

## Installation

```bash
pip install pygments-cedar
```

## Usage

Once installed, the lexer registers itself as a Pygments plugin. It is automatically available anywhere Pygments is used.

### Command line

```bash
pygmentize -l cedar policy.cedar
```

### Python

```python
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name

lexer = get_lexer_by_name("cedar")
code = '''
permit(
  principal == User::"alice",
  action == Action::"view",
  resource == Photo::"VacationPhoto94.jpg"
);
'''
print(highlight(code, lexer, HtmlFormatter()))
```

### Markdown (e.g. MkDocs, Sphinx)

Use the `cedar` language identifier in fenced code blocks:

````markdown
```cedar
permit(
  principal == User::"alice",
  action == Action::"view",
  resource == Photo::"VacationPhoto94.jpg"
);
```
````

## Supported syntax

- Policy effects: `permit`, `forbid`
- Scope keywords: `principal`, `action`, `resource`, `context`
- Condition clauses: `when`, `unless`
- Operators: `in`, `has`, `like`, `is`, `if`/`then`/`else`, logical (`&&`, `||`, `!`), comparison (`==`, `!=`, `<`, `>`, `<=`, `>=`)
- Entity references: `Namespace::Type::"id"`
- Strings with escape sequences
- Integer literals (including negative)
- Line comments (`//`)
- Function/method calls

## Development

Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).

```bash
uv sync
uv run pytest tests/ -v
```

## License

BSD 2-Clause. See [LICENSE](LICENSE) for details.
