https://tree-sitter.github.io/tree-sitter/
git submodule update --init --recursive
phpize
./configure
make
make test
make installextension=treesitter.so has to be added to your PHP ini file.
use TreeSitter as TS;
$parser = new TS\Parser(TS\Grammar::JSON);
$tree = $parser->parse("[1, null]");
$rootNode = $tree->getRootNode();
echo $rootNode; // (document (array (number) (null)))Creates a new Parser object with the given TreeSitter\Grammar grammar. See built-in parser grammars in the Parsers section below.
Parses the source code and produces a TreeSitter\Tree instance or throws TreeSitter\SyntaxError exception.
Parses the source code and returns TreeSitter\Tree instance with error nodes.
Returns the root TreeSitter\Node instance that contains the AST (Abstract Syntax Tree).
Returns the type of the node as per the grammar selected.
Whether this node has any children or not.
Return the number of children this node has.
The start byte for this node within the $source_code. Note that the position will include multibyte characters. See ::getStartPoint. Is relative to the root.
The end byte for this node within the $source_code. Note that the result will count multibyte characters as individual bytes. See ::getEndPoint. Is relative to the root.
Returns a TreeSitter\Point instance with the int $row and int $column properties set to the starting point of this node, taking into account multi-byte characters. Is relative to the root.
Returns a TreeSitter\Point instance with the int $row and int $column properties set to the ending point of this node, taking into account multi-byte characters. Is relative to the root.
Ouputs the S-expression syntax tree for the current node and its siblings.
The row within the source tree. See TreeSitter\Node::getStartPoint() and TreeSitter\Node::getEndPoint().
The column within the source tree. See TreeSitter\Node::getStartPoint() and TreeSitter\Node::getEndPoint().
Extends Exception. Thrown from TreeSitter\Parser::parse if a syntax error is detected.
This extension includes the following parsers:
| Parser | Constant |
|---|---|
| PHP | TreeSitter\Grammar::PHP |
| HTML | TreeSitter\Grammar::HTML |
| CSS | TreeSitter\Grammar::CSS |
| JavaScript & JSX | TreeSitter\Grammar::JAVASCRIPT |
| TypeScript & TSX | TreeSitter\Grammar::TYPESCRIPT |
| JSON | TreeSitter\Grammar::JSON |
| Python | TreeSitter\Grammar::PYTHON |
ext-treesitter is undergoing initial heavy development and is highly unstable.
Missing something? File an issue and/or open a PR.