#php #parser #ast-node

backyard-parser

Parse PHP code to AST node

7 releases

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

#366 in Programming languages

Download history 192/week @ 2024-11-23 71/week @ 2024-11-30 536/week @ 2024-12-07 192/week @ 2024-12-14 10/week @ 2024-12-21

739 downloads per month
Used in backyard-generator

MIT license

375KB
10K SLoC

backyard-parser

Parse PHP code to AST node.

features

  • Parse string to AST (parse() & parse_eval())

usage

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

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

Notice this output is not including leadings, trailings and location because we print it with print(false, false), more on backyard-nodes.

ProgramNode
└-children[]-FunctionNode
    ├-is_ref: false-name
    │ └-IdentifierNode
    │   └-name: "hello_world"-parameters[]
    │ ╙-ParameterNode
    │   ├-variable_type: -
    │   ├-is_ref: false
    │   ├-is_ellipsis: false
    │   ├-name
    │   │ └-IdentifierNode
    │   │   └-name: "foo"
    │   └-value: --return_type: --body
      └-BlockNode
        └-statements[]-CallNode
            ├-name
            │ └-IdentifierNode
            │   └-name: "var_dump"-arguments[]-CallArgumentNode
                ├-name: --value
                  └-VariableNode
                    └-name
                      └-IdentifierNode
                        └-name: "foo"

ecosystem

heavily inspired by

license

MIT

Dependencies

~1–1.7MB
~32K SLoC