Skip to content

feat: Comprehensive YARA language support upgrade (Grammar, Outlines, Folding, and Highlighting) - #2

Open
binjo wants to merge 3 commits into
egibs:mainfrom
binjo:main
Open

feat: Comprehensive YARA language support upgrade (Grammar, Outlines, Folding, and Highlighting)#2
binjo wants to merge 3 commits into
egibs:mainfrom
binjo:main

Conversation

@binjo

@binjo binjo commented Jun 29, 2026

Copy link
Copy Markdown

Title

feat: Comprehensive YARA language support upgrade (Grammar, Outlines, Folding, and Highlighting)

Description

This Pull Request delivers a massive upgrade to the yara.zed extension, bringing it to full feature-parity with advanced editors. It replaces the basic syntax highlighter with a robust, syntactically complete YARA development environment by upgrading the tree-sitter grammar, adding structured navigation queries, patching edge-case syntax bugs, and optimizing syntax highlighting.


Key Enhancements & Changes since Fork

1. ⚙️ Parser & Grammar Upgrade

  • Namespace & Member Access Support: Replaced the incomplete egibs/tree-sitter-yara parser with celstur/tree-sitter-yara. This adds support for standard module namespaces, dot member accesses, and native function calls (e.g., pe.is_dll(), math.entropy()), resolving syntax-highlighting breakage on complex rules.
  • Anonymous Variable Indexing Bug Fix: Resolved an issue where the parser choked on array-style index lookups on anonymous offsets (@) and lengths (!) (e.g., @[j] or ![j]), producing a syntax error block.
Upstream Grammar Patch details for grammar.js:

To resolve this inside the tree-sitter parser, grammar.js was modified to make bracketed index sequences optional on anonymous offsets and lengths:

string_offset: ($) =>
  seq(
    token(/@[a-zA-Z0-9_]*/),
    optional(seq($._lbrack, $._numeric_expression, $._rbrack))
  ),
string_length: ($) =>
  seq(
    token(/![a-zA-Z0-9_]*/),
    optional(seq($._lbrack, $._numeric_expression, $._rbrack))
  ),

The parser was then re-generated (npx tree-sitter generate) to update src/parser.c to fully support modern, complex rule indexing.

2. 🎨 Enhanced Syntax Highlighting (highlights.scm)

  • Mapped standard library module namespaces (like pe, math, elf) cleanly to @type.
  • Mapped members/fields to @function to represent them as callable components rather than plain strings.
  • Added native #match? regular expression queries to highlight standard built-in functions dynamically (e.g. uint16, uint32be, etc.).
  • Stripped literal operators like "!", "#" and "@" from query delimiters to prevent tree-sitter parser load rejections.

3. 📁 Structural Editor Features (Emacs yara-mode Parity)

  • Document Outline (outline.scm): Added outline matches to display defined rule headers in Zed's Symbol/Outline navigation search (Ctrl/Cmd + Shift + O).
  • Smart Auto-Indents (indents.scm): Structured and aligned block-indentation scopes for rule_body, meta_section, strings_section, and condition_section.
  • Code Folding (folds.scm): Enabled vertical collapsing/folding on both rule-level blocks and individual sections (meta, strings, condition) to make analyzing large files easy.

Verification and Testing

All layers of this upgrade have been tested and verified inside Zed:

  1. Parser & Highlights: Verified syntax rendering and AST accuracy across standard and complex rule datasets.
  2. Editor Queries: Successfully verified rule folding, auto-indentation on bracket insertion, and rule outline indexing.

binjo added 3 commits June 29, 2026 13:38
- Upgrade tree-sitter-yara parser to celstur fork
- Implement folding, outline, and smart indentation queries
- Fix syntax highlighting rules and add modern keyword support
- Patch grammar issues with anonymous indexing variables
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.

1 participant