parser/README.md

76 lines
1.5 KiB
Markdown
Raw Normal View History

# PHP-Parser
2022-07-20 21:35:03 +02:00
A handwritten recursive-descent parser for PHP written in Rust, for fun.
2022-11-27 17:48:12 +01:00
2022-11-30 15:42:44 +01:00
[![justforfunnoreally.dev badge](https://img.shields.io/badge/justforfunnoreally-dev-9ff)](https://justforfunnoreally.dev)
> **Warning**: This crate is not ready for any form of production use _yet_. There are still a lot of things missing from the parser, so please use at your own risk.
2022-09-12 01:32:25 +02:00
---
2022-09-12 01:28:42 +02:00
## Usage
Add `php-parser-rs` in your `Cargo.toml`'s `dependencies` section
```toml
[dependencies]
php-parser-rs = "0.0.0-b1"
```
2022-11-30 15:43:25 +01:00
or use `cargo add`
```sh
cargo add php-parser-rs
```
### Example
2022-11-27 03:47:07 +01:00
```rust
use php_parser_rs::parse;
use php_parser_rs::lexer::Lexer;
2022-11-27 03:47:07 +01:00
fn main() -> ParseResult<()> {
let lexer = Lexer::new();
2022-11-27 03:47:07 +01:00
let code = "
<?php
function hello(): void {
echo 'Hello, World!';
}
hello();
";
let tokens = lexer.tokenize(code.as_bytes())?;
let ast = parse(tokens)?;
dbg!(ast);
Ok(())
}
2022-11-27 03:47:07 +01:00
```
2022-11-27 03:51:28 +01:00
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
2022-09-12 01:42:34 +02:00
at your option.
2022-09-12 01:42:34 +02:00
## Contribution
2022-09-12 01:42:34 +02:00
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
2022-09-12 01:42:34 +02:00
## Credits
2022-09-12 01:42:34 +02:00
* [Ryan Chandler](https://github.com/ryangjchandler)
* [All contributors](https://github.com/ryangjchandler/php-parser-rs/graphs/contributors)