tree-sitter-php
repository·master·Indexed 42 days ago
https://github.com/tree-sitter/tree-sitter-phpA 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.
What's inside tree-sitter-php
- tree-sitter-php provides a PHP grammar for the tree-sitter incremental parsing library. It allows developers to build high-performance syntax trees for PHP code, enabling features like syntax highlighting, code navigation, and structural analysis.
Use the Node.js bindings for tree-sitter-php
masterThe
tree-sitter-phpNode.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 withbun build --compileby allowing static analysis to locate the.nodebinary.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);Access node type metadata for PHP grammars
masterThe Node.js bindings expose metadata about the available node types for both the standard
phpgrammar and thephp_onlygrammar. This metadata is stored in thenodeTypeInfoproperty of the respective language object and is loaded fromnode-types.jsonfiles within the package.php.nodeTypeInfo: Metadata for the standard PHP grammar.php_only.nodeTypeInfo: Metadata for thephp_onlygrammar.
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;