tree-sitter-blade

repository·main·Indexed 42 days ago

https://github.com/emranmr/tree-sitter-blade

A high-performance Tree-Sitter grammar for Laravel Blade templates, version 0.12.0. It enables advanced syntax highlighting, code folding, and language injection in editors such as Nova, Neovim, and Zed. The package provides Node.js bindings and a rewritten grammar that inherits from HTML for improved performance and semantic structure.

Tokens
637
Snippets
1
Records
7
Agent score
4%

What's inside tree-sitter-blade

  1. Understanding Queries and Capture Groups

    main

    The repository contains a queries/ folder, but note that your specific editor or service may use different capture group names or predicates than those defined here.

    Important Note for Nova users: Nova does not use the files in the queries/ folder; it uses its own internal Queries folder instead.

    If your editor is not highlighting or folding correctly, you may need to consult your editor's documentation to determine how it maps Tree-Sitter queries to its own internal capture groups.

  2. Upgrade to v0.12.0 or later

    main

    If you are upgrading from a version prior to v0.12.0, be aware that the grammar has been completely rewritten.

    Key changes include:

    • The grammar now inherits html and manages the html tree structure.
    • Significant performance improvements (up to 10x faster).
    • A more semantic and leaner grammar structure.

    Refer to the official v0.12.0 Release Note for the full upgrade guide.

  3. Reporting issues

    main

    If you encounter parsing errors or incorrect syntax highlighting, raise an issue on GitHub. To help the maintainer, include as much of the following as possible:

    • Code Excerpts: The specific code causing the issue.
    • Photos: A screenshot of the visual issue.
    • Parse Tree: If your editor allows you to inspect the tree, provide the output.
  4. Use tree-sitter-blade in Node.js

    main

    The tree-sitter-blade package provides Node.js bindings for the Blade grammar. It can be required directly in a Node.js or Bun environment. The package automatically handles platform-specific prebuilds via node-gyp-build or provides static analysis support for bun build --compile by locating the .node binary based on the current platform and architecture.

    Additionally, the package exports a nodeTypeInfo object containing metadata about the grammar's node types, which is useful for debugging or advanced parsing logic.

    const parser = require('tree-sitter-blade');
    
    // Access node type information if needed
    console.log(parser.nodeTypeInfo);