Skip to main content

A Pygments plugin providing syntax highlighting for YARA-L 2.0, a language used to create detection rules for Google Security Operations (SecOps)

Project description

pygments-lexer-yara-l

A Pygments plugin providing syntax highlighting for YARA-L 2.0, a language used to create detection rules for Google Security Operations (SecOps).

Features

  • Syntax highlighting for all YARA-L 2.0 constructs
  • Supports section keywords (rule, meta, events, match, outcome, condition, options, order, limit, stage, dedup, select, unselect)
  • Supports operator keywords (and, or, not, nocase, over, before, after, of, in, any, all, if, regex, cidr, by, asc, desc, AND, OR)
  • Supports boolean/null constants (true, false, null)
  • Highlights all built-in namespaced functions (strings.*, re.*, math.*, net.*, timestamp.*, arrays.*, cast.*, hash.*, bytes.*, window.*, metrics.*, optimization.*)
  • Highlights aggregate functions (count, count_distinct, sum, avg, max, min, stddev, array, array_distinct, group)
  • Highlights UDM/graph field paths ($e.principal.hostname → variable + attribute tokens)
  • Handles all string types: double-quoted strings with escape sequences, back-quoted raw strings, and regex literals
  • Handles line comments (//) and block comments (/* */)
  • Auto-detection heuristics based on common YARA-L patterns
  • Registered as a Pygments plugin via pygments.lexers entry point

Installation

pip install pygments-lexer-yara-l

Usage

Once installed, the lexer is automatically available to Pygments via the plugin entry point. You can use it with any Pygments-compatible tool.

Command line (pygmentize)

pygmentize -l yaral my_rule.yaral
pygmentize -l yara-l my_rule.yaral

Python API

from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments_lexer_yaral import YaraLLexer

code = open('my_rule.yaral').read()
print(highlight(code, YaraLLexer(), TerminalFormatter()))

Terminal preview

python preview.py
DEBUG=1 python preview.py   # Print each token and its type

Visual preview server

pip install 'pygments-lexer-yara-l[server]'
python server.py
# Then open http://localhost:8080

Supported aliases

Alias Description
yaral Primary alias
yara-l Alternative alias

File extension

.yaral

MIME type

text/x-yaral

Development

git clone https://github.com/seanthegeek/pygments-lexer-yara-l.git
cd pygments-lexer-yara-l
pip install -e ".[dev,server]"
make test

License

MIT License. See LICENSE for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygments_lexer_yara_l-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygments_lexer_yara_l-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pygments_lexer_yara_l-0.1.0.tar.gz.

File metadata

File hashes

Hashes for pygments_lexer_yara_l-0.1.0.tar.gz
Algorithm Hash digest
SHA256 21604f54d7bb679949292a0615c866f93e0799f85624395d72bc670887759833
MD5 d10b02f9635429cf8397e2c0bfd2ba39
BLAKE2b-256 a3292b819e2b4bc81c45f328cf579d612233c1f852c283a1d22860ef8b93f468

See more details on using hashes here.

File details

Details for the file pygments_lexer_yara_l-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pygments_lexer_yara_l-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d13077df6d2ba4422e426a2f88238e7181543b8931c97e14ecc395262c45a81a
MD5 96268ec6465f519664552e84c49eb5d3
BLAKE2b-256 8ab5378babd11a66a3327ec50194e5e23088cda4a3a650d29ece9589ae1f6701

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page