diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db005aa..e3329a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,27 @@ jobs: uses: tree-sitter/parser-setup-action@v1.2 - name: Run tests uses: tree-sitter/parser-test-action@v1.2 + with: + test-library: ${{runner.os == 'Linux'}} + + parse-examples: + name: Parse examples + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Set up tree-sitter + uses: tree-sitter/parser-setup-action@v1.2 + with: + fetch-depth: 1 + submodules: true + - name: Parse examples + uses: tree-sitter/parse-action@3a4b1262a5fe2aa8e644e3f9c42059f2f382f2ed + with: + files-list: test/files.txt + invalid-files-list: test/invalid-files.txt test-swift: name: Test Swift binding diff --git a/.gitignore b/.gitignore index 4aa85f4..76c6a61 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,6 @@ dist/ *.dll *.pc -# Example dirs -/examples/*/ - # Grammar volatiles *.wasm *.obj diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7d1185 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,57 @@ +[submodule "examples/0install"] + path = examples/0install + url = https://github.com/0install/0install +[submodule "examples/bap"] + path = examples/bap + url = https://github.com/BinaryAnalysisPlatform/bap +[submodule "examples/cmdliner"] + path = examples/cmdliner + url = https://github.com/dbuenzli/cmdliner +[submodule "examples/pyre-check"] + path = examples/pyre-check + url = https://github.com/facebook/pyre-check +[submodule "examples/lablgtk"] + path = examples/lablgtk + url = https://github.com/garrigue/lablgtk +[submodule "examples/base"] + path = examples/base + url = https://github.com/janestreet/base +[submodule "examples/melange"] + path = examples/melange + url = https://github.com/melange-re/melange +[submodule "examples/ocaml-cohttp"] + path = examples/ocaml-cohttp + url = https://github.com/mirage/ocaml-cohttp +[submodule "examples/dune"] + path = examples/dune + url = https://github.com/ocaml/dune +[submodule "examples/merlin"] + path = examples/merlin + url = https://github.com/ocaml/merlin +[submodule "examples/ocaml"] + path = examples/ocaml + url = https://github.com/ocaml/ocaml +[submodule "examples/ocaml-lsp"] + path = examples/ocaml-lsp + url = https://github.com/ocaml/ocaml-lsp +[submodule "examples/opam"] + path = examples/opam + url = https://github.com/ocaml/opam +[submodule "examples/eio"] + path = examples/eio + url = https://github.com/ocaml-multicore/eio +[submodule "examples/ocamlformat"] + path = examples/ocamlformat + url = https://github.com/ocaml-ppx/ocamlformat +[submodule "examples/ppxlib"] + path = examples/ppxlib + url = https://github.com/ocaml-ppx/ppxlib +[submodule "examples/js_of_ocaml"] + path = examples/js_of_ocaml + url = https://github.com/ocsigen/js_of_ocaml +[submodule "examples/lwt"] + path = examples/lwt + url = https://github.com/ocsigen/lwt +[submodule "examples/owl"] + path = examples/owl + url = https://github.com/owlbarn/owl diff --git a/examples/.gitkeep b/examples/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/examples/0install b/examples/0install new file mode 160000 index 0000000..225587e --- /dev/null +++ b/examples/0install @@ -0,0 +1 @@ +Subproject commit 225587eef889a3082e0cc53fa64500f56cca0028 diff --git a/examples/bap b/examples/bap new file mode 160000 index 0000000..f969db3 --- /dev/null +++ b/examples/bap @@ -0,0 +1 @@ +Subproject commit f969db3d795baa15965faff7de192e436424729e diff --git a/examples/base b/examples/base new file mode 160000 index 0000000..1311ac1 --- /dev/null +++ b/examples/base @@ -0,0 +1 @@ +Subproject commit 1311ac11d54b79698c8d559d1334b0b815757788 diff --git a/examples/cmdliner b/examples/cmdliner new file mode 160000 index 0000000..c229193 --- /dev/null +++ b/examples/cmdliner @@ -0,0 +1 @@ +Subproject commit c2291939d4ca65c77985d7d5eb07512ba2fe89e1 diff --git a/examples/dune b/examples/dune new file mode 160000 index 0000000..58d1cd3 --- /dev/null +++ b/examples/dune @@ -0,0 +1 @@ +Subproject commit 58d1cd35495deed1b7b4487f5149a9364ecc8024 diff --git a/examples/eio b/examples/eio new file mode 160000 index 0000000..14ae3cf --- /dev/null +++ b/examples/eio @@ -0,0 +1 @@ +Subproject commit 14ae3cfee30a546ec6521b4576029dfe19f85869 diff --git a/examples/js_of_ocaml b/examples/js_of_ocaml new file mode 160000 index 0000000..d2cf189 --- /dev/null +++ b/examples/js_of_ocaml @@ -0,0 +1 @@ +Subproject commit d2cf189e575c9d161f3c65baf5b6349b5e7670a0 diff --git a/examples/lablgtk b/examples/lablgtk new file mode 160000 index 0000000..e2d564b --- /dev/null +++ b/examples/lablgtk @@ -0,0 +1 @@ +Subproject commit e2d564ba13c781b68a7f03dd275b50d332c7f3b3 diff --git a/examples/lwt b/examples/lwt new file mode 160000 index 0000000..73f1a0f --- /dev/null +++ b/examples/lwt @@ -0,0 +1 @@ +Subproject commit 73f1a0f0acd5540f25e58bc410e1f63271189c6c diff --git a/examples/melange b/examples/melange new file mode 160000 index 0000000..01d6ba4 --- /dev/null +++ b/examples/melange @@ -0,0 +1 @@ +Subproject commit 01d6ba45bd2acd852bff4f3dd3f05e5c1abbcea5 diff --git a/examples/merlin b/examples/merlin new file mode 160000 index 0000000..b274d31 --- /dev/null +++ b/examples/merlin @@ -0,0 +1 @@ +Subproject commit b274d31dd047a80240a8007b4c1ca45b548ccabf diff --git a/examples/ocaml b/examples/ocaml new file mode 160000 index 0000000..18c4510 --- /dev/null +++ b/examples/ocaml @@ -0,0 +1 @@ +Subproject commit 18c4510e6c8693c1feffb4871f429987a1d714ff diff --git a/examples/ocaml-cohttp b/examples/ocaml-cohttp new file mode 160000 index 0000000..cf2ae33 --- /dev/null +++ b/examples/ocaml-cohttp @@ -0,0 +1 @@ +Subproject commit cf2ae3344ed9211230a5680f251613326eacb296 diff --git a/examples/ocaml-lsp b/examples/ocaml-lsp new file mode 160000 index 0000000..ad20957 --- /dev/null +++ b/examples/ocaml-lsp @@ -0,0 +1 @@ +Subproject commit ad209576feb8127e921358f2e286e68fd60345e7 diff --git a/examples/ocamlformat b/examples/ocamlformat new file mode 160000 index 0000000..6ce00bf --- /dev/null +++ b/examples/ocamlformat @@ -0,0 +1 @@ +Subproject commit 6ce00bf1ac5faa8b8e56dc1c08c693b50529a72a diff --git a/examples/opam b/examples/opam new file mode 160000 index 0000000..eafdc81 --- /dev/null +++ b/examples/opam @@ -0,0 +1 @@ +Subproject commit eafdc8187676f4669d5e702317a2c5bb79225019 diff --git a/examples/owl b/examples/owl new file mode 160000 index 0000000..c66069e --- /dev/null +++ b/examples/owl @@ -0,0 +1 @@ +Subproject commit c66069eed06405f98d5a12465c15542ba882347a diff --git a/examples/ppxlib b/examples/ppxlib new file mode 160000 index 0000000..455f217 --- /dev/null +++ b/examples/ppxlib @@ -0,0 +1 @@ +Subproject commit 455f21787ad52a32813a34538a4d493f8d3efc64 diff --git a/examples/pyre-check b/examples/pyre-check new file mode 160000 index 0000000..5cd77ed --- /dev/null +++ b/examples/pyre-check @@ -0,0 +1 @@ +Subproject commit 5cd77ed7e7f4443420a5f546394129a1bc9c4d30 diff --git a/package.json b/package.json index 7f45be0..ed52645 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "test-ocaml": "cd grammars/ocaml && tree-sitter test", "test-interface": "cd grammars/interface && tree-sitter test", "test-highlight": "tree-sitter test", - "parse": "tree-sitter parse" + "parse": "tree-sitter parse", + "parse-examples": "test/parse-examples.sh" }, "tree-sitter": [ { diff --git a/script/parse-examples b/script/parse-examples deleted file mode 100755 index e7aedb4..0000000 --- a/script/parse-examples +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -set -e - -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 - head=$(git rev-parse HEAD) - if [ "$head" != "$sha" ]; then - echo "Updating $owner/$name from $head to $sha" - git fetch - git reset --hard $sha - fi - popd > /dev/null -} - -clone_repo 0install 0install 225587eef889a3082e0cc53fa64500f56cca0028 -clone_repo BinaryAnalysisPlatform bap 0e3966ae027c72f0e1f2463afd132d9f10821d40 -clone_repo dbuenzli cmdliner b2f03ea0427feaae59e2a0e02ff020f0d78ccbcf -clone_repo facebook flow 30855cad7ee6e6117b2b495d005ee95e1a11f9b4 -clone_repo facebook pyre-check e73ca136a9d7150ea4606505ee3d732e227ddd83 -clone_repo garrigue lablgtk 7e41440382b064bf3cf40f6efff493ce05250a84 -clone_repo janestreet base a2b9340b5b2bf8df935422d14e03e497e6e8c98f -clone_repo mirage ocaml-cohttp 16e991ec1f7e5f0c99615cd1f58b99b02e3d0499 -clone_repo ocaml dune e7a1d844ddf4ac8cfc82f6dfa1657799d338a9b6 -clone_repo ocaml merlin 8f1d3f1be970663495a21b83c66bac9934351c82 -clone_repo ocaml ocaml d9547617e8b14119beacafaa2546cbebfac1bfe5 -clone_repo ocaml ocaml-lsp e81d16a72a4dceaf2e28fefe7db40b6553e3d4e7 -clone_repo ocaml opam f539e4c6fb00f3aabcb5ed10bbe1d1e49dd2abb7 -clone_repo ocaml-ppx ocamlformat 3d62b5841f2777642e8a0e34422a0a55667b3a67 -clone_repo ocaml-ppx ppxlib e9077667078f55e8a67f1406691c450b30e5a6ba -clone_repo ocsigen js_of_ocaml e1fe3e955c30cb8b305cb1b65b1eaa4c700267b1 -clone_repo ocsigen lwt cc05e2bda6c34126a3fd8d150ee7cddb3b8a440b -clone_repo owlbarn owl 48434ea744d8e5f488a56bb06ecd15659c58f186 - -known_failures="$(cat script/known_failures.txt)" - -tree-sitter parse -q \ - 'examples/**/*.ml' \ - 'examples/**/*.mli' \ - $(for failure in $known_failures; do echo "!${failure}"; done) - -example_count=$(find examples -name '*.ml' -o -name '*.mli' | 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 diff --git a/test/files.txt b/test/files.txt new file mode 100644 index 0000000..8e2001b --- /dev/null +++ b/test/files.txt @@ -0,0 +1,6 @@ +examples/**/*.ml +examples/**/*.mli +!examples/**/*.cppo.* +!examples/ocamlformat/test/failing/**/* +!examples/ocamlformat/test/passing/**/* +!examples/ocaml/testsuite/tests/parse-errors/**/* diff --git a/script/known_failures.txt b/test/invalid-files.txt similarity index 70% rename from script/known_failures.txt rename to test/invalid-files.txt index 089f778..233a80d 100644 --- a/script/known_failures.txt +++ b/test/invalid-files.txt @@ -2,47 +2,34 @@ examples/lablgtk/applications/osiris/osiris.ml examples/lablgtk/examples/csview.ml examples/lablgtk/tools/introspection/stubs/stubs_Atk.ml examples/lablgtk/tools/introspection/stubs/stubs_Pango.ml -examples/lwt/src/react/lwt_react.cppo.ml -examples/lwt/src/unix/lwt_unix.cppo.ml -examples/lwt/src/unix/lwt_unix.cppo.mli -examples/lwt/test/unix/test_lwt_unix.cppo.ml +examples/melange/bin/melc.ml examples/merlin/tests/test-dirs/completion/infix.t/infix.ml examples/merlin/tests/test-dirs/completion/parenthesize.t/parenthesize.ml examples/merlin/tests/test-dirs/construct/c-modules.t/functor_app.ml examples/merlin/tests/test-dirs/construct/c-modules.t/module.ml examples/merlin/tests/test-dirs/errors/typing-after-parsing.t/test.ml -examples/merlin/tests/test-dirs/locate/context-detection/cd-label.t/label.ml +examples/merlin/tests/test-dirs/type-enclosing/issueLSP695.t/main.ml examples/ocaml/stdlib/templates/float.template.mli examples/ocaml/stdlib/templates/moreLabels.template.mli examples/ocaml/testsuite/tests/generated-parse-errors/errors.ml examples/ocaml/testsuite/tests/lexing/escape.ml examples/ocaml/testsuite/tests/lexing/uchar_esc.ml -examples/ocaml/testsuite/tests/parse-errors/* -examples/ocaml/testsuite/tests/parsing/anonymous_class_parameter.ml examples/ocaml/testsuite/tests/parsing/arrow_ambiguity.ml examples/ocaml/testsuite/tests/parsing/constructor_declarations.ml examples/ocaml/testsuite/tests/parsing/docstrings.ml -examples/ocaml/testsuite/tests/parsing/pr6604_2.ml examples/ocaml/testsuite/tests/parsing/pr6604.ml +examples/ocaml/testsuite/tests/parsing/pr6604_2.ml +examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting.ml examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting_use2.ml examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting_use3.ml -examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting.ml examples/ocaml/testsuite/tests/typing-misc/typecore_errors.ml examples/ocaml/testsuite/tests/typing-sigsubst/sig_local_aliases_syntax_errors.ml -examples/ocaml/testsuite/tests/typing-sigsubst/sig_local_aliases.ml examples/ocaml/testsuite/tests/typing-warnings/pr7261.ml -examples/ocamlformat/test/failing/*/* -examples/ocamlformat/test/passing/*/* examples/ocamlformat/test/rpc/big_margin/foo.ml -examples/ocamlformat/vendor/parser-recovery/test/expect/signature/*.mli -examples/ocamlformat/vendor/parser-recovery/test/expect/structure/*.ml examples/ppxlib/astlib/astlib.ml examples/ppxlib/astlib/location.ml examples/ppxlib/astlib/longident.ml -examples/ppxlib/test/code_path/test.ml examples/ppxlib/test/driver/non-compressible-suffix/test.ml +examples/ppxlib/test/expansion_helpers/mangle/test.ml examples/ppxlib/test/ppx_import_support/test.ml examples/ppxlib/test/quoter/test.ml -examples/opam/src/core/opamCompat.ml -examples/opam/src/core/opamCompat.mli -examples/ppxlib/test/expansion_helpers/mangle/test.ml diff --git a/test/parse-examples.sh b/test/parse-examples.sh new file mode 100755 index 0000000..daa2644 --- /dev/null +++ b/test/parse-examples.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -ef + +cd "$(dirname "$0")/.." + +git submodule update --init --depth 1 + +tree-sitter parse -q -s \ + $(cat test/files.txt) \ + $(for file in $(cat test/invalid-files.txt); do echo "!${file}"; done)