backyard-nodes

Crates.iobackyard-nodes
lib.rsbackyard-nodes
version
sourcesrc
created_at2024-11-27 13:00:20.338515
updated_at2024-12-12 08:45:43.511592
descriptionNodes representing PHP code AST.
homepage
repositoryhttps://github.com/Alzera/backyard
max_upload_size
id1462990
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Alzera Cita (Alzera)

documentation

README

backyard-nodes

Nodes representing PHP code AST, with simple builder and walker.

features

  • Ast Nodes
  • "builder" simplify building AST nodes
  • "walker" simple walker through AST nodes

usage

builder

This builder is behind the builder feature.

use backyard_nodes::builder::{ Builder, BlueprintBuildable };
fn main() {
  let arena = bumpalo::Bump::new();
  let b = Builder::new();
  let node = b
    .Program(&[b.Assignment(b.Variable(b.Identifier("a")), "=", b.Number("21"))])
    .build(&arena);
  println!("{node:?}");
}

Resulting this:

Node {
  node_type: Program,
  wrapper: Program(ProgramNode {
    children: [
      Node {
        node_type: Assignment,
        wrapper: Assignment(AssignmentNode {
          left: Node {
            node_type: Variable,
            wrapper: Variable(VariableNode {
              name: Node {
                node_type: Identifier,
                wrapper: Identifier(IdentifierNode { name: "a" }),
                loc: None, leadings: None, trailings: None
              }
            }),
            loc: None, leadings: None, trailings: None
          },
          operator: "=",
          right: Node {
            node_type: Number,
            wrapper: Number(NumberNode { value: "21" }),
            loc: None, leadings: None, trailings: None
          }
        }),
        loc: None, leadings: None, trailings: None
      }]
    }),
  loc: None, leadings: None, trailings: None
}

walker

This builder is behind the walker feature.

use backyard_nodes::{ builder::{ BlueprintBuildable, Builder }, walker::Walker, NodeType };

fn main() {
  let arena = bumpalo::Bump::new();
  let b = Builder::new();
  let node = b
    .Program(&[b.Assignment(b.Variable(b.Identifier("a")), "=", b.Number("21"))])
    .build(&arena);
  let mut walker = Walker::new(&*node).into_iter();

  assert_eq!(NodeType::Program, walker.next().unwrap().node_type);
  assert_eq!(NodeType::Assignment, walker.next().unwrap().node_type);
  assert_eq!(NodeType::Variable, walker.next().unwrap().node_type);
  assert_eq!(NodeType::Identifier, walker.next().unwrap().node_type);
  assert_eq!(NodeType::Number, walker.next().unwrap().node_type);
  assert!(walker.next().is_none());
}

ecosystem

heavily inspired by

license

MIT

Commit count: 158

cargo fmt