diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml
new file mode 100644
index 0000000..9a3553f
--- /dev/null
+++ b/.github/workflows/benchmark.yaml
@@ -0,0 +1,44 @@
+name: Benchmark
+
+on:
+ pull_request: null
+ push:
+ branches:
+ - main
+ schedule:
+ # every 12 hours
+ - cron: '0 */12 * * *'
+
+jobs:
+ corpus:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@v2
+ with:
+ workspaces: |
+ .
+ bench/mago
+ - uses: actions/setup-go@v5
+ with:
+ go-version: "1.26.6"
+ cache: false
+
+ - name: Clone + install Laravel corpus
+ run: |
+ git clone --depth 1 https://github.com/laravel/framework laravel
+ composer install --no-interaction --no-progress --ignore-platform-reqs --working-dir=laravel
+ # drop intentionally-broken PHP fixtures
+ rm -rf laravel/tests
+ find laravel/vendor -depth -type d -name tests -exec rm -rf {} +
+
+ - name: Run benchmark (php-parser-in-rust vs php-parser-in-go vs mago-syntax)
+ run: |
+ {
+ echo "## Corpus benchmark"
+ echo ""
+ echo "Parsing the full Laravel framework (\`src/\` + Composer \`vendor/\`)."
+ echo ""
+ bench/compare.sh laravel 5
+ } | tee -a "$GITHUB_STEP_SUMMARY"
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
new file mode 100644
index 0000000..350b5cf
--- /dev/null
+++ b/.github/workflows/tests.yaml
@@ -0,0 +1,43 @@
+name: Tests
+
+on:
+ pull_request: null
+ push:
+ branches:
+ - main
+
+jobs:
+ tests:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/rust-toolchain@stable
+ with:
+ components: rustfmt, clippy
+ - uses: Swatinem/rust-cache@v2
+
+ - run: cargo fmt --check
+ - run: cargo clippy --all-targets -- -D warnings
+ - run: cargo test
+
+ # parse the Laravel corpus with both parsers and require identical dumps
+ go_parity:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@v2
+ - uses: actions/setup-go@v5
+ with:
+ go-version: "1.26.6"
+ cache-dependency-path: tools/go-oracle/go.sum
+
+ - name: Clone + install Laravel corpus
+ run: |
+ git clone --depth 1 https://github.com/laravel/framework laravel
+ composer install --no-interaction --no-progress --ignore-platform-reqs --working-dir=laravel
+ rm -rf laravel/tests
+ find laravel/vendor -depth -type d -name tests -exec rm -rf {} +
+
+ - run: tools/diff-corpus.sh 8.4 laravel
+ - run: tools/diff-corpus.sh 7.4 laravel
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fa12bf6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+/.claude
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..3d624c5
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "php_parser"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..dda81d0
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "php_parser"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+
+[profile.release]
+codegen-units = 1
+lto = true
diff --git a/README.md b/README.md
index 2e9f6af..1d4db46 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,61 @@
# php-parser-in-rust
-A PHP parser written in Rust, a port of [rectorphp/php-parser-in-go](https://github.com/rectorphp/php-parser-in-go). It lexes and parses PHP 5, 7 and 8 source into the same AST, so both can be compared on speed.
+A PHP parser written in Rust, a port of [rectorphp/php-parser-in-go](https://github.com/rectorphp/php-parser-in-go). It lexes and parses PHP 5, 7 and 8 source into the same AST as the Go parser, so both can be compared on speed.
-Work in progress.
+## Benchmark
+
+Parsing the full Laravel framework (`src/` + Composer `vendor/`, 18157 files) on 4 cores, average over 5 runs, in CI:
+
+| Parser | Avg | Peak mem |
+|:-------|----:|---------:|
+| php-parser-in-rust | 1186 ms | 153 MB |
+| [php-parser-in-go](https://github.com/rectorphp/php-parser-in-go) | 2557 ms | 4428 MB |
+| [mago-syntax](https://crates.io/crates/mago-syntax) | 536 ms | 151 MB |
+
+- The Go benchmark runs with the GC disabled, which explains most of its memory.
+- mago-syntax allocates each tree in an arena and builds its own CST; it has no PHP version setting. The others parse as PHP 8.3 into the Go AST.
+
+CI reruns this on every push and every 12 hours, see the **Summary** of the Benchmark workflow. Run it locally on any corpus:
+
+```bash
+bench/compare.sh ./laravel
+```
+
+## Usage
+
+```rust
+use php_parser::{parse, Config, version::Version};
+use php_parser::visitor::dumper::Dumper;
+
+let source = b"
` - dumps a whole corpus with the Go oracle (`tools/go-oracle`) and the Rust parser and diffs them. CI runs it on Laravel at PHP 8.4 and 7.4.
+
+Valid files go through hand-written recursive descent parsers. A file with a syntax error is parsed again by a port of the Go grammar tables, so error messages and recovered trees match Go too.
+
+## Credits
+
+Port of [rectorphp/php-parser-in-go](https://github.com/rectorphp/php-parser-in-go), which is based on [z7zmey/php-parser](https://github.com/z7zmey/php-parser).
diff --git a/bench/compare.sh b/bench/compare.sh
new file mode 100755
index 0000000..62124cc
--- /dev/null
+++ b/bench/compare.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# Parse every .php file of a corpus with php-parser-in-rust, php-parser-in-go and
+# mago-syntax, and print a markdown table of average wall-clock and peak memory:
+# bench/compare.sh [runs]
+set -euo pipefail
+
+dir=$1
+runs=${2:-5}
+root=$(cd "$(dirname "$0")/.." && pwd)
+bin="$root/target/bench"
+mkdir -p "$bin"
+
+cargo build --release --quiet --manifest-path "$root/Cargo.toml" --bin benchmark
+cp "$root/target/release/benchmark" "$bin/rust"
+
+cargo build --release --quiet --manifest-path "$root/bench/mago/Cargo.toml"
+cp "$root/bench/mago/target/release/bench-mago" "$bin/mago"
+
+if [ ! -d "$bin/php-parser-in-go" ]; then
+ git clone --quiet --depth 1 https://github.com/rectorphp/php-parser-in-go "$bin/php-parser-in-go"
+fi
+(cd "$bin/php-parser-in-go" && go build -o "$bin/go" ./benchmark)
+
+# average wall-clock in ms, as reported by the benchmark itself
+average() {
+ total=0
+ for _ in $(seq 1 "$runs"); do
+ ms=$("$@" | awk '{print $5}')
+ total=$((total + ms))
+ done
+ echo $((total / runs))
+}
+
+# peak resident set size in MB of a single run
+peak_memory() {
+ /usr/bin/time -v "$@" 2> "$bin/mem.log" > /dev/null
+ awk '/Maximum resident set size/{printf "%d", $NF/1024}' "$bin/mem.log"
+}
+
+files=$("$bin/rust" "$dir" | awk '{print $2}')
+
+echo "Parsing $files files on $(nproc) cores, average over $runs runs."
+echo ""
+echo "| Parser | Avg | Peak mem |"
+echo "|:-------|----:|---------:|"
+for parser in rust go mago; do
+ case $parser in
+ rust) name="php-parser-in-rust" ;;
+ go) name="php-parser-in-go" ;;
+ mago) name="mago-syntax" ;;
+ esac
+ echo "| $name | $(average "$bin/$parser" "$dir") ms | $(peak_memory "$bin/$parser" "$dir") MB |"
+done
diff --git a/bench/mago/.gitignore b/bench/mago/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/bench/mago/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/bench/mago/Cargo.lock b/bench/mago/Cargo.lock
new file mode 100644
index 0000000..8afa61f
--- /dev/null
+++ b/bench/mago/Cargo.lock
@@ -0,0 +1,919 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "aho-corasick"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "allocator-api2"
+version = "0.2.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57b212daf2e827b1ccdd778b7eb48ba433e58cb0e4f27b43cd6b7a608425a014"
+
+[[package]]
+name = "ariadne"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8454c8a44ce2cb9cc7e7fae67fc6128465b343b92c6631e94beca3c8d1524ea5"
+dependencies = [
+ "unicode-width",
+ "yansi",
+]
+
+[[package]]
+name = "arrayvec"
+version = "0.7.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47a64a0fd06e123e9e3cf3ad01432af17dcab8185e8023edcf184fe696f9675d"
+
+[[package]]
+name = "autocfg"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
+
+[[package]]
+name = "bench-mago"
+version = "0.1.0"
+dependencies = [
+ "mago-allocator",
+ "mago-database",
+ "mago-syntax",
+]
+
+[[package]]
+name = "bitflags"
+version = "2.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
+
+[[package]]
+name = "blake3"
+version = "1.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68fe79e887dd9b3d00ffb29973ff39df3d99b81e6fefbde49636989bd56264d6"
+dependencies = [
+ "arrayvec",
+ "cc",
+ "cfg-if",
+ "constant_time_eq",
+ "cpufeatures",
+]
+
+[[package]]
+name = "blink-alloc"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e669f146bb8b2327006ed94c69cf78c8ec81c100192564654230a40b4f091d82"
+dependencies = [
+ "allocator-api2",
+ "parking_lot",
+]
+
+[[package]]
+name = "bstr"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a680398c10c7bc0488067c4612226ea905a85f607134b69f3068d505d58c4214"
+dependencies = [
+ "memchr",
+ "serde_core",
+]
+
+[[package]]
+name = "cc"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66"
+dependencies = [
+ "find-msvc-tools",
+ "shlex",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
+
+[[package]]
+name = "codespan-reporting"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"
+dependencies = [
+ "serde",
+ "termcolor",
+ "unicode-width",
+]
+
+[[package]]
+name = "constant_time_eq"
+version = "0.6.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "144e7f1de087984240b7816d47f698b414979faa6f40839c5b86d6bd47db57b7"
+dependencies = [
+ "rustversion",
+]
+
+[[package]]
+name = "cpufeatures"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
+dependencies = [
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
+
+[[package]]
+name = "dyn-clone"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
+
+[[package]]
+name = "either"
+version = "1.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
+
+[[package]]
+name = "equivalent"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
+
+[[package]]
+name = "find-msvc-tools"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8"
+
+[[package]]
+name = "foldhash"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
+
+[[package]]
+name = "glob"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
+
+[[package]]
+name = "globset"
+version = "0.4.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "71217a07f20b48b4938c14203b77b610f8a7fa6762c3f75394a10c5f31e5aee0"
+dependencies = [
+ "aho-corasick",
+ "bstr",
+ "log",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.17.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc"
+dependencies = [
+ "allocator-api2",
+ "equivalent",
+ "foldhash",
+]
+
+[[package]]
+name = "heck"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
+[[package]]
+name = "ignore"
+version = "0.4.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df0a7d5f105e76bda602bed0a44af048542d3c9af12ec35aaf16f106c6f34270"
+dependencies = [
+ "crossbeam-deque",
+ "globset",
+ "log",
+ "memchr",
+ "regex-automata",
+ "same-file",
+ "walkdir",
+ "winapi-util",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.14.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
+name = "inotify"
+version = "0.11.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4cc00ea907cab49550b7da656f80ebb97be1b997d931fbcd28d39734e17ce592"
+dependencies = [
+ "bitflags",
+ "inotify-sys",
+ "libc",
+]
+
+[[package]]
+name = "inotify-sys"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c033f80b2c113cdf91ab7a33faa9cbc014726dcad99880c8609af2a370edf37d"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
+
+[[package]]
+name = "kqueue"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8d763e5b24120b4ddf50de6c92308156765aabfbbccebf401da7cff2d70a41ea"
+dependencies = [
+ "kqueue-sys",
+ "libc",
+]
+
+[[package]]
+name = "kqueue-sys"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07293a4e297ac234359b510362495713f75ea345d5307140414f20c69ffeb087"
+dependencies = [
+ "bitflags",
+ "libc",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.191"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
+
+[[package]]
+name = "lock_api"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
+dependencies = [
+ "scopeguard",
+]
+
+[[package]]
+name = "log"
+version = "0.4.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
+
+[[package]]
+name = "mago-allocator"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "906ba8c14b843ca92e70532412febae26a7cbe92103e09cd5635404f132e1baa"
+dependencies = [
+ "allocator-api2",
+ "blink-alloc",
+ "hashbrown",
+]
+
+[[package]]
+name = "mago-database"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4beeb7cc32d1f2488bad45ddde94e675fda581ea4ac7b1df01d0ddf3618a583f"
+dependencies = [
+ "foldhash",
+ "glob",
+ "globset",
+ "ignore",
+ "memchr",
+ "notify",
+ "rayon",
+ "tracing",
+ "walkdir",
+]
+
+[[package]]
+name = "mago-php-version"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c68e87807c567b99927a2e0e38b1fa93f69241cc1cbc6a1e7bd5278434a916d"
+dependencies = [
+ "schemars",
+]
+
+[[package]]
+name = "mago-reporting"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca8a6676f00014b26fa61d2d460fbfe49fe6311722678272eda4a866a3c9f0a3"
+dependencies = [
+ "ariadne",
+ "blake3",
+ "codespan-reporting",
+ "foldhash",
+ "itoa",
+ "mago-database",
+ "mago-span",
+ "mago-text-edit",
+ "memchr",
+ "rayon",
+ "regex",
+ "schemars",
+ "strum",
+ "termcolor",
+ "tracing",
+]
+
+[[package]]
+name = "mago-span"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d54d737bf46a31ba755306d0c6b91659ab953b9642673c2286fbd0b59bd39b45"
+dependencies = [
+ "mago-database",
+]
+
+[[package]]
+name = "mago-syntax"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7cde5e2e7c57f7e847e7451864b8c8fb46b066a1f000de6cb093f23a1f7d7448"
+dependencies = [
+ "mago-allocator",
+ "mago-database",
+ "mago-php-version",
+ "mago-reporting",
+ "mago-span",
+ "mago-syntax-core",
+ "memchr",
+ "ordered-float",
+ "paste",
+ "strum",
+]
+
+[[package]]
+name = "mago-syntax-core"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "12d628de6c9939cccb6fedc206498c5221c81dd4fa322676b51b83df6bffbd02"
+dependencies = [
+ "mago-allocator",
+ "mago-database",
+ "mago-span",
+ "memchr",
+]
+
+[[package]]
+name = "mago-text-edit"
+version = "1.62.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d509599a718c9b94f0bc071cb5106be8763ce4730d4885f4eafce1b77f1a398a"
+
+[[package]]
+name = "memchr"
+version = "2.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
+
+[[package]]
+name = "mio"
+version = "1.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a"
+dependencies = [
+ "libc",
+ "log",
+ "wasi",
+ "windows-sys",
+]
+
+[[package]]
+name = "notify"
+version = "8.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c41a04a5f59df9322cc657286dd2d79f90816119b22c5f847607c850110205ab"
+dependencies = [
+ "bitflags",
+ "inotify",
+ "kqueue",
+ "libc",
+ "log",
+ "mio",
+ "notify-types",
+ "objc2-core-foundation",
+ "objc2-core-services",
+ "walkdir",
+ "windows-sys",
+]
+
+[[package]]
+name = "notify-types"
+version = "2.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cbd044e85df3d939d8e32a1c35a3b737c7d0a4eeb7acd737bd207644e00f4e5f"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "objc2-core-foundation"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "objc2-core-services"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "583300ad934cba24ff5292aee751ecc070f7ca6b39a574cc21b7b5e588e06a0b"
+dependencies = [
+ "libc",
+ "objc2-core-foundation",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.21.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+
+[[package]]
+name = "ordered-float"
+version = "5.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f59006ce1e204c30956638535b74d317bca99477b9356dfaec54c37f6f600ab"
+dependencies = [
+ "num-traits",
+ "rand",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.12.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
+dependencies = [
+ "lock_api",
+ "parking_lot_core",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.9.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "windows-link",
+]
+
+[[package]]
+name = "paste"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
+
+[[package]]
+name = "pin-project-lite"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.107"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rand"
+version = "0.8.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
+dependencies = [
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+
+[[package]]
+name = "rayon"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
+dependencies = [
+ "crossbeam-deque",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.5.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "ref-cast"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3"
+dependencies = [
+ "ref-cast-impl",
+]
+
+[[package]]
+name = "ref-cast-impl"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.10",
+]
+
+[[package]]
+name = "regex"
+version = "1.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
+
+[[package]]
+name = "rustversion"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
+
+[[package]]
+name = "same-file"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "schemars"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e"
+dependencies = [
+ "dyn-clone",
+ "ref-cast",
+ "schemars_derive",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "schemars_derive"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1c3a92094fa7d61aa124645844facb6b554dfc797136d0f5fd1f890e2bffc69"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde_derive_internals",
+ "syn 3.0.10",
+]
+
+[[package]]
+name = "scopeguard"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+
+[[package]]
+name = "serde"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.10",
+]
+
+[[package]]
+name = "serde_derive_internals"
+version = "0.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f852137cce035d6a4df67ccce505ff6b3e9fd3a10e3e52b24dc71e650bb1a9bd"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.10",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.154"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
+dependencies = [
+ "foldhash",
+ "indexmap",
+ "itoa",
+ "memchr",
+ "serde",
+ "serde_core",
+ "zmij",
+]
+
+[[package]]
+name = "shlex"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
+
+[[package]]
+name = "smallvec"
+version = "1.16.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
+
+[[package]]
+name = "strum"
+version = "0.28.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd"
+dependencies = [
+ "strum_macros",
+]
+
+[[package]]
+name = "strum_macros"
+version = "0.28.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.119"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "3.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "termcolor"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "tracing"
+version = "0.1.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
+dependencies = [
+ "pin-project-lite",
+ "tracing-attributes",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-attributes"
+version = "0.1.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "tracing-core"
+version = "0.1.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
+
+[[package]]
+name = "unicode-width"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca718471876992059f251e33aafc334346ada08042b7661dd1fe313a9bced557"
+
+[[package]]
+name = "walkdir"
+version = "2.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b42e295b7452c4604982280d8586001fcad9b8b201cac67bca9771e7a7475403"
+dependencies = [
+ "same-file",
+ "winapi-util",
+]
+
+[[package]]
+name = "wasi"
+version = "0.11.1+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "windows-link"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+
+[[package]]
+name = "windows-sys"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "yansi"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
+
+[[package]]
+name = "zmij"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
diff --git a/bench/mago/Cargo.toml b/bench/mago/Cargo.toml
new file mode 100644
index 0000000..f7a8683
--- /dev/null
+++ b/bench/mago/Cargo.toml
@@ -0,0 +1,17 @@
+[package]
+name = "bench-mago"
+version = "0.1.0"
+edition = "2024"
+publish = false
+
+[dependencies]
+mago-allocator = "1.62.0"
+mago-database = "1.62.0"
+mago-syntax = "1.62.0"
+
+[profile.release]
+codegen-units = 1
+lto = true
+
+# standalone, so mago stays out of the parser's dependencies
+[workspace]
diff --git a/bench/mago/src/main.rs b/bench/mago/src/main.rs
new file mode 100644
index 0000000..48383f5
--- /dev/null
+++ b/bench/mago/src/main.rs
@@ -0,0 +1,68 @@
+//! Corpus benchmark for mago-syntax: parse every .php file under the given path
+//! across all cores and report the wall-clock time, the same way as the
+//! php-parser-in-rust and php-parser-in-go benchmarks.
+
+use std::path::{Path, PathBuf};
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::time::Instant;
+
+use mago_allocator::LocalArena;
+use mago_database::file::FileId;
+use mago_syntax::parser::parse_file_content;
+
+fn main() {
+ let root = std::env::args().nth(1).unwrap_or_else(|| ".".to_string());
+
+ let mut files = Vec::new();
+ collect_php_files(Path::new(&root), &mut files);
+
+ let start = Instant::now();
+ let parsed = parse_all(&files);
+ let elapsed = start.elapsed();
+
+ println!("parsed {parsed} files in {} ms", elapsed.as_millis());
+}
+
+fn parse_all(files: &[PathBuf]) -> usize {
+ let next = AtomicUsize::new(0);
+ let parsed = AtomicUsize::new(0);
+ let workers = std::thread::available_parallelism().map_or(1, |n| n.get());
+
+ std::thread::scope(|scope| {
+ for _ in 0..workers {
+ scope.spawn(|| {
+ loop {
+ let index = next.fetch_add(1, Ordering::Relaxed);
+ let Some(path) = files.get(index) else { break };
+ let Ok(content) = std::fs::read(path) else {
+ continue;
+ };
+ // a fresh arena per file, like a fresh tree per file in the other benchmarks
+ let arena = LocalArena::new();
+ let program = parse_file_content(&arena, FileId::zero(), &content);
+ std::hint::black_box(program);
+ parsed.fetch_add(1, Ordering::Relaxed);
+ }
+ });
+ }
+ });
+
+ parsed.into_inner()
+}
+
+fn collect_php_files(dir: &Path, files: &mut Vec) {
+ let Ok(entries) = std::fs::read_dir(dir) else {
+ return;
+ };
+ for entry in entries.flatten() {
+ let Ok(file_type) = entry.file_type() else {
+ continue;
+ };
+ let path = entry.path();
+ if file_type.is_dir() {
+ collect_php_files(&path, files);
+ } else if file_type.is_file() && path.extension().is_some_and(|ext| ext == "php") {
+ files.push(path);
+ }
+ }
+}
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
new file mode 100644
index 0000000..23786c1
--- /dev/null
+++ b/src/ast/mod.rs
@@ -0,0 +1,47 @@
+use std::any::Any;
+use std::collections::HashMap;
+use std::fmt;
+
+mod name;
+mod nodes;
+
+pub use name::{is_reserved_type, to_string};
+pub use nodes::*;
+
+/// Metadata assigned to a node after parsing, such as a resolved type. The map
+/// is allocated lazily, so a node that never gets one costs a single word.
+#[derive(Default)]
+#[allow(clippy::box_collection)]
+pub struct Attributes(Option>>>);
+
+impl Attributes {
+ /// Store `value` under `key`.
+ pub fn set(&mut self, key: impl Into, value: T) {
+ self.0
+ .get_or_insert_with(Default::default)
+ .insert(key.into(), Box::new(value));
+ }
+
+ /// Value stored under `key`, if present and of type `T`.
+ pub fn get(&self, key: &str) -> Option<&T> {
+ self.0.as_ref()?.get(key)?.downcast_ref()
+ }
+
+ /// Whether a value is stored under `key`.
+ pub fn has(&self, key: &str) -> bool {
+ self.0.as_ref().is_some_and(|map| map.contains_key(key))
+ }
+
+ pub fn is_empty(&self) -> bool {
+ self.0.as_ref().is_none_or(|map| map.is_empty())
+ }
+}
+
+impl fmt::Debug for Attributes {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match &self.0 {
+ None => f.write_str("{}"),
+ Some(map) => f.debug_set().entries(map.keys()).finish(),
+ }
+ }
+}
diff --git a/src/ast/name.rs b/src/ast/name.rs
new file mode 100644
index 0000000..61f39ec
--- /dev/null
+++ b/src/ast/name.rs
@@ -0,0 +1,43 @@
+use crate::ast::Node;
+
+/// Source text of a name node - a Name, NameFullyQualified or NameRelative
+/// joined by "\", a NamePart or Identifier value, or "" for any other node. The
+/// leading separator of a fully qualified name is not included.
+pub fn to_string(node: &Node<'_>) -> String {
+ match node {
+ Node::Name(n) => parts_to_string(n.parts.as_deref()),
+ Node::NameFullyQualified(n) => parts_to_string(n.parts.as_deref()),
+ Node::NameRelative(n) => parts_to_string(n.parts.as_deref()),
+ Node::NamePart(n) => lossy(n.value.as_deref()),
+ Node::Identifier(n) => lossy(n.value.as_deref()),
+ _ => String::new(),
+ }
+}
+
+fn lossy(value: Option<&[u8]>) -> String {
+ String::from_utf8_lossy(value.unwrap_or_default()).into_owned()
+}
+
+fn parts_to_string(parts: Option<&[Node<'_>]>) -> String {
+ let mut segments = Vec::new();
+ for part in parts.unwrap_or_default() {
+ if let Node::NamePart(name_part) = part {
+ segments.push(lossy(name_part.value.as_deref()));
+ }
+ }
+ segments.join("\\")
+}
+
+const RESERVED_TYPES: [&str; 17] = [
+ "int", "float", "string", "bool", "void", "array", "iterable", "callable", "object", "mixed",
+ "never", "null", "false", "true", "self", "static", "parent",
+];
+
+/// Whether `name` is a PHP reserved type keyword (a scalar, array, callable,
+/// void, never, mixed, or a self/static/parent relative type), matched
+/// case-insensitively. Such a name is a builtin type, not a class reference.
+pub fn is_reserved_type(name: &str) -> bool {
+ RESERVED_TYPES
+ .iter()
+ .any(|reserved| reserved.eq_ignore_ascii_case(name))
+}
diff --git a/src/ast/nodes.rs b/src/ast/nodes.rs
new file mode 100644
index 0000000..dc5d3e9
--- /dev/null
+++ b/src/ast/nodes.rs
@@ -0,0 +1,4172 @@
+// Generated from the Go AST definitions; do not edit by hand.
+
+use crate::ast::Attributes;
+use crate::position::Position;
+use crate::token::{Bytes, Token};
+
+/// Root node
+#[derive(Debug, Default)]
+pub struct Root<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub stmts: Option>>,
+ pub end_tkn: Option>,
+}
+
+/// Nullable node
+#[derive(Debug, Default)]
+pub struct Nullable<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub question_tkn: Option>,
+ pub expr: Option>,
+}
+
+/// Union node holds a union type such as `int|string`, its member types
+/// separated by `|`.
+#[derive(Debug, Default)]
+pub struct Union<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub types: Option>>,
+ pub separator_tkns: Option>>,
+}
+
+/// Intersection node holds an intersection type such as `Countable&Traversable`,
+/// its member types separated by `&`. In a DNF type the intersection is wrapped
+/// in parentheses, e.g. `(A&B)|C`; the parenthesis tokens are then set.
+#[derive(Debug, Default)]
+pub struct Intersection<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub open_parenthesis_tkn: Option>,
+ pub types: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+}
+
+/// Parameter node
+#[derive(Debug, Default)]
+pub struct Parameter<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub modifiers: Option>>,
+ pub r#type: Option>,
+ pub ampersand_tkn: Option>,
+ pub variadic_tkn: Option>,
+ pub var: Option>,
+ pub equal_tkn: Option>,
+ pub default_value: Option>,
+ /// OpenCurlyBracketTkn, Hooks and CloseCurlyBracketTkn hold the property
+ /// hooks of a constructor-promoted parameter; Hooks is nil when it has none.
+ pub open_curly_bracket_tkn: Option>,
+ pub hooks: Option>>,
+ pub close_curly_bracket_tkn: Option>,
+}
+
+/// PropertyHook node: a `get` or `set` hook of a property. The body is either
+/// Stmt (a statement list), DoubleArrowTkn and Expr closed by SemiColonTkn, or
+/// a lone SemiColonTkn for an abstract hook.
+#[derive(Debug, Default)]
+pub struct PropertyHook<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub modifiers: Option>>,
+ pub ampersand_tkn: Option>,
+ pub name: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub params: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub double_arrow_tkn: Option>,
+ pub expr: Option>,
+ pub stmt: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// Identifier node
+#[derive(Debug, Default)]
+pub struct Identifier<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub identifier_tkn: Option>,
+ pub value: Option>,
+}
+
+/// Argument node
+/// Argument is one call argument. A placeholder of partial function application
+/// (`?`, `name: ?`, or a bare `...`) has no Expr: PlaceholderTkn or VariadicTkn is set.
+#[derive(Debug, Default)]
+pub struct Argument<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub name: Option>,
+ pub colon_tkn: Option>,
+ pub variadic_tkn: Option>,
+ pub placeholder_tkn: Option>,
+ pub ampersand_tkn: Option>,
+ pub expr: Option>,
+}
+
+/// Attribute node
+#[derive(Debug, Default)]
+pub struct Attribute<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub name: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub args: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+}
+
+/// AttributeGroup node
+#[derive(Debug, Default)]
+pub struct AttributeGroup<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub open_attribute_tkn: Option>,
+ pub attrs: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_attribute_tkn: Option>,
+}
+
+/// StmtBreak node
+#[derive(Debug, Default)]
+pub struct StmtBreak<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub break_tkn: Option>,
+ pub expr: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtCase node
+#[derive(Debug, Default)]
+pub struct StmtCase<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub case_tkn: Option>,
+ pub cond: Option>,
+ pub case_separator_tkn: Option>,
+ pub stmts: Option>>,
+}
+
+/// StmtCatch node
+#[derive(Debug, Default)]
+pub struct StmtCatch<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub catch_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub types: Option>>,
+ pub separator_tkns: Option>>,
+ pub var: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub open_curly_bracket_tkn: Option>,
+ pub stmts: Option>>,
+ pub close_curly_bracket_tkn: Option>,
+}
+
+/// StmtClass node
+#[derive(Debug, Default)]
+pub struct StmtClass<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub modifiers: Option>>,
+ pub class_tkn: Option>,
+ pub name: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub args: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub extends_tkn: Option>,
+ pub extends: Option>,
+ pub implements_tkn: Option>,
+ pub implements: Option>>,
+ pub implements_separator_tkns: Option>>,
+ pub open_curly_bracket_tkn: Option>,
+ pub stmts: Option>>,
+ pub close_curly_bracket_tkn: Option>,
+}
+
+/// StmtClassConstList node
+#[derive(Debug, Default)]
+pub struct StmtClassConstList<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub modifiers: Option>>,
+ pub const_tkn: Option>,
+ pub r#type: Option>,
+ pub consts: Option>>,
+ pub separator_tkns: Option>>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtClassMethod node
+#[derive(Debug, Default)]
+pub struct StmtClassMethod<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub modifiers: Option>>,
+ pub function_tkn: Option>,
+ pub ampersand_tkn: Option>,
+ pub name: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub params: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub return_type: Option>,
+ pub stmt: Option>,
+}
+
+/// StmtConstList node
+#[derive(Debug, Default)]
+pub struct StmtConstList<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub const_tkn: Option>,
+ pub consts: Option>>,
+ pub separator_tkns: Option>>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtConstant node
+#[derive(Debug, Default)]
+pub struct StmtConstant<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub name: Option>,
+ pub equal_tkn: Option>,
+ pub expr: Option>,
+}
+
+/// StmtContinue node
+#[derive(Debug, Default)]
+pub struct StmtContinue<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub continue_tkn: Option>,
+ pub expr: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtDeclare node
+#[derive(Debug, Default)]
+pub struct StmtDeclare<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub declare_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub consts: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+ pub end_declare_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtDefault node
+#[derive(Debug, Default)]
+pub struct StmtDefault<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub default_tkn: Option>,
+ pub case_separator_tkn: Option>,
+ pub stmts: Option>>,
+}
+
+/// StmtDo node
+#[derive(Debug, Default)]
+pub struct StmtDo<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub do_tkn: Option>,
+ pub stmt: Option>,
+ pub while_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub cond: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtEcho node
+#[derive(Debug, Default)]
+pub struct StmtEcho<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub echo_tkn: Option>,
+ pub exprs: Option>>,
+ pub separator_tkns: Option>>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtElse node
+#[derive(Debug, Default)]
+pub struct StmtElse<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub else_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+}
+
+/// StmtElseIf node
+#[derive(Debug, Default)]
+pub struct StmtElseIf<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub else_if_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub cond: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+}
+
+/// StmtExpression node
+#[derive(Debug, Default)]
+pub struct StmtExpression<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub expr: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtFinally node
+#[derive(Debug, Default)]
+pub struct StmtFinally<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub finally_tkn: Option>,
+ pub open_curly_bracket_tkn: Option>,
+ pub stmts: Option>>,
+ pub close_curly_bracket_tkn: Option>,
+}
+
+/// StmtFor node
+#[derive(Debug, Default)]
+pub struct StmtFor<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub for_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub init: Option>>,
+ pub init_separator_tkns: Option>>,
+ pub init_semi_colon_tkn: Option>,
+ pub cond: Option>>,
+ pub cond_separator_tkns: Option>>,
+ pub cond_semi_colon_tkn: Option>,
+ pub r#loop: Option>>,
+ pub loop_separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+ pub end_for_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtForeach node
+#[derive(Debug, Default)]
+pub struct StmtForeach<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub foreach_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub expr: Option>,
+ pub as_tkn: Option>,
+ pub key: Option>,
+ pub double_arrow_tkn: Option>,
+ pub ampersand_tkn: Option>,
+ pub var: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+ pub end_foreach_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtFunction node
+#[derive(Debug, Default)]
+pub struct StmtFunction<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub attr_groups: Option>>,
+ pub function_tkn: Option>,
+ pub ampersand_tkn: Option>,
+ pub name: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub params: Option>>,
+ pub separator_tkns: Option>>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub return_type: Option>,
+ pub open_curly_bracket_tkn: Option>,
+ pub stmts: Option>>,
+ pub close_curly_bracket_tkn: Option>,
+}
+
+/// StmtGlobal node
+#[derive(Debug, Default)]
+pub struct StmtGlobal<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub global_tkn: Option>,
+ pub vars: Option>>,
+ pub separator_tkns: Option>>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtGoto node
+#[derive(Debug, Default)]
+pub struct StmtGoto<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub goto_tkn: Option>,
+ pub label: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtHaltCompiler node
+#[derive(Debug, Default)]
+pub struct StmtHaltCompiler<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub halt_compiler_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtIf node
+#[derive(Debug, Default)]
+pub struct StmtIf<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub if_tkn: Option>,
+ pub open_parenthesis_tkn: Option>,
+ pub cond: Option>,
+ pub close_parenthesis_tkn: Option>,
+ pub colon_tkn: Option>,
+ pub stmt: Option>,
+ pub else_if: Option>>,
+ pub r#else: Option>,
+ pub end_if_tkn: Option>,
+ pub semi_colon_tkn: Option>,
+}
+
+/// StmtInlineHtml node
+#[derive(Debug, Default)]
+pub struct StmtInlineHtml<'a> {
+ pub attributes: Attributes,
+ pub position: Option,
+ pub inline_html_tkn: Option