Skip to content

Commit

Permalink
chore: update Cargo.toml and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 18, 2023
1 parent f593804 commit b44dc66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "tree-sitter-php"
description = "php grammar for the tree-sitter parsing library"
version = "0.19.1"
description = "PHP grammar for tree-sitter"
keywords = ["incremental", "parsing", "php"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-php"
edition = "2018"
edition = "2021"
license = "MIT"

build = "bindings/rust/build.rs"
Expand All @@ -15,7 +15,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">= 0.20, < 0.21"
tree-sitter = "~0.20.10"

[build-dependencies]
cc = "1.0"
cc = "~1.0.83"
41 changes: 17 additions & 24 deletions bindings/rust/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
# tree-sitter-php
# tree-sitter-c

This crate provides support of the PHP language for the [tree-sitter][] parsing library. To use this crate, add it to
the `[dependencies]` section of your
`Cargo.toml` file. As this crate is not (yet) published to the central registry, you will have to specify it as a git
dependency, currently we suggest using the `master` branch.
This crate provides a C grammar for the [tree-sitter][] parsing library. To
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
file. (Note that you will probably also need to depend on the
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
way.)

You will also need the [tree-sitter crate][] to do the actual parsing here.

``` toml
```toml
[dependencies]
tree-sitter = "0.19"
tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php.git", branch = "master" }
tree-sitter = "0.20.10"
tree-sitter-php = "0.20.6"
```

To you the parser, you need to obtain an instance of a [`tree_sitter::Language`][Language] struct for php.
The `language()` function provides this.
Passing this struct to a [`tree_sitter::Parser`][Parser] will enable it to parse PHP.
Typically, you will use the [language][language func] function to add this
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:

``` rust
```rust
use tree_sitter::Parser;

fn main() {
let code = r#"
<?php
function double(int $x) {
return $x * 2;
}
"#;
let mut parser = Parser::new();
parser
.set_language(tree_sitter_php::language())
.expect("Error loading PHP parsing support");
parser.set_language(tree_sitter_php::language()).expect("Error loading PHP grammar");
let parsed = parser.parse(code, None);
println!("{:#?}", parsed);
}
```

If you have any questions, please reach out to us in the [tree-sitter discussions] page.

[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
If you have any questions, please reach out to us in the [tree-sitter
discussions] page.

[language func]: https://docs.rs/tree-sitter-c/*/tree_sitter_c/fn.language.html
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html

[tree-sitter]: https://tree-sitter.github.io/

[tree-sitter crate]: https://crates.io/crates/tree-sitter

[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions

0 comments on commit b44dc66

Please sign in to comment.