Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add example parsing script #53

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed example-file.blade
Empty file.
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
81 changes: 42 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
{
"name": "tree-sitter-blade",
"version": "0.9.2",
"description": "tree-sitter-blade grammar for Laravel Blade files",
"main": "bindings/node",
"keywords": [
"tree-sitter-blade",
"name": "tree-sitter-blade",
"version": "0.9.2",
"description": "tree-sitter-blade grammar for Laravel Blade files",
"main": "bindings/node",
"keywords": [
"tree-sitter-blade",
"blade",
"tree-sitter",
"laravel"
],
"homepage": "https://github.com/EmranMR/tree-sitter-blade",
"repository": {
"type": "git",
"url": "https://github.com/EmranMR/tree-sitter-blade"
},
"bugs": "https://github.com/EmranMR/tree-sitter-blade/issues",
"funding": "https://github.com/sponsors/EmranMR",
"scripts": {
"build": "tree-sitter generate",
"test": "tree-sitter test",
"test-examples": "script/parse-examples"
},
"author": "Emran Mashhadi Ramezan",
"license": "MIT",
"dependencies": {
"nan": "^2.17.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
{
"scope": "source.blade.php",
"file-types": [
"blade",
"tree-sitter",
"laravel"
],
"homepage": "https://github.com/EmranMR/tree-sitter-blade",
"repository": {
"type": "git",
"url": "https://github.com/EmranMR/tree-sitter-blade"
},
"bugs": "https://github.com/EmranMR/tree-sitter-blade/issues",
"funding": "https://github.com/sponsors/EmranMR",
"scripts": {
"test": "tree-sitter generate && tree-sitter test",
"parse": "tree-sitter generate && tree-sitter parse example-file.blade",
"generate": "tree-sitter generate"
},
"author": "Emran Mashhadi Ramezan",
"license": "MIT",
"dependencies": {
"nan": "^2.17.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
{
"scope": "source.blade.php",
"file-types": [
"blade",
"php"
],
"injection-regex": "blade"
}
]
"php"
],
"injection-regex": "blade",
"highlights": "queries/highlights.scm",
"injections": "queries/injections-text.scm",
"folds": "queries/folds.scm"
}
]
}
2 changes: 2 additions & 0 deletions script/known-failures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
examples/breeze/stubs/default/resources/views/components/input-error.blade.php
examples/breeze/stubs/default/resources/views/components/modal.blade.php
44 changes: 44 additions & 0 deletions script/parse-examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -eu

cd "$(dirname "$0")/.."

function clone_repo {
owner=$1
name=$2
sha=$3

path=examples/$name
if [ ! -d "$path" ]; then
echo "Cloning $owner/$name"
git clone "https://github.com/$owner/$name" "$path"
fi

pushd "$path" >/dev/null
actual_sha=$(git rev-parse HEAD)
if [ "$actual_sha" != "$sha" ]; then
echo "Updating $owner/$name to $sha"
git fetch
git reset --hard "$sha"
fi
popd >/dev/null
}

clone_repo laravel breeze 4dce985b91081bd0bfd31c612bdbb0fd2187a89b

known_failures=$(cat script/known-failures.txt)

# shellcheck disable=2046
tree-sitter parse -q --scope source.blade.php \
examples/**/*.blade.php \
$(for file in $known_failures; do echo "!${file}"; done)

example_count=$(find examples -name '*.blade.php' | wc -l)
failure_count=$(wc -w <<<"$known_failures")
success_count=$((example_count - failure_count))
success_percent=$(bc -l <<<"100*${success_count}/${example_count}")

printf \
"Successfully parsed %d of %d example files (%.1f%%)\n" \
$success_count $example_count $success_percent