Skip to content

Commit

Permalink
Merge pull request #53 from calebdw/parse_examples
Browse files Browse the repository at this point in the history
chore: add example parsing script
  • Loading branch information
EmranMR authored Feb 14, 2024
2 parents 4c66efe + e37f27b commit 4ea4026
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 39 deletions.
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

0 comments on commit 4ea4026

Please sign in to comment.