#!/bin/bash

set -e

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

known_failures="$(cat script/known_failures.txt)"

tree-sitter parse -q \
  'examples/**/*.rs' \
  $(for file in $known_failures; do echo "!${file}"; done)

example_count=$(find examples -name '*.rs' | 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
