tree-sitter-php

repository·master·Indexed 42 days ago

https://github.com/tree-sitter/tree-sitter-php

A PHP grammar implementation for the tree-sitter incremental parsing library, version 0.24.2, used to parse PHP source code into a concrete syntax tree for syntax highlighting, code navigation, and structural analysis.

Tokens
520
Snippets
2
Records
3
Agent score
4%

What's inside tree-sitter-php

  1. Use the Node.js bindings for tree-sitter-php

    master

    The tree-sitter-php Node.js module provides access to the PHP grammar. It automatically detects the appropriate prebuilt binary for your platform and architecture. If you are using Bun, it is designed to be compatible with bun build --compile by allowing static analysis to locate the .node binary.

    The module exports the language objects, which include metadata about node types available in the grammar.

    const Parser = require('tree-sitter');
    const PHP = require('tree-sitter-php');
    
    const parser = new Parser();
    parser.setLanguage(PHP);
    
    // The PHP language object also contains nodeTypeInfo metadata
    console.log(PHP.nodeTypeInfo);
  2. Access node type metadata for PHP grammars

    master

    The Node.js bindings expose metadata about the available node types for both the standard php grammar and the php_only grammar. This metadata is stored in the nodeTypeInfo property of the respective language object and is loaded from node-types.json files within the package.

    • php.nodeTypeInfo: Metadata for the standard PHP grammar.
    • php_only.nodeTypeInfo: Metadata for the php_only grammar.
    const PHP = require('tree-sitter-php');
    const PHPOnly = require('tree-sitter-php').php_only;
    
    // Accessing node type information
    const phpNodeTypes = PHP.nodeTypeInfo;
    const phpOnlyNodeTypes = PHPOnly.nodeTypeInfo;