#php #parser #ast-node #convert #back #comments

backyard-generator

Convert AST node back to PHP code

7 releases

0.1.10 Dec 17, 2024
0.1.9 Dec 12, 2024
0.1.5 Nov 29, 2024

#477 in Algorithms

Download history 105/week @ 2024-11-22 148/week @ 2024-11-29 488/week @ 2024-12-06 220/week @ 2024-12-13 13/week @ 2024-12-20

723 downloads per month

MIT license

415KB
11K SLoC

backyard-generator

Convert AST node back to PHP code.

features

  • Convert AST back to string (generate())

usage

let arena = bumpalo::Bump::new();
let code = r#"<?php
// leading comment
function hello_world($foo) {
  var_dump($foo);
}"#;

let parsed = backyard_parser::parse(&arena, code).unwrap();
let generated = backyard_generator::generate(&parsed).unwrap();
println!("{:?}", generated);

Resulting this code:

// leading comment
function hello_world($foo) {
  var_dump($foo);
}

ecosystem

heavily inspired by

license

MIT

Dependencies

~1–1.8MB
~34K SLoC