From b33112a43e500eb6e07fe3214c18de75a9234ca8 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 12:51:15 +1000 Subject: [PATCH 1/7] Disable bnfc --tree-sitter by default If needed and you have bnfc-treesitter fork installed, you can re-generate the tree-sitter grammar.js with: BINCAML_BNFC_TREESITTER=true dune runtest tree-sitter --auto-promote I should also add the bnfc-treesitter fork to the nix devshell, but i'll avoid doing that for now because it would conflict with the revert PR. --- tree-sitter/dune | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tree-sitter/dune b/tree-sitter/dune index ca13dd0c..dc2376e7 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -10,10 +10,13 @@ ; check that grammar.js is up to date. ; requires `bnfc-treesitter` from pac-nix. +; bnfc tree-sitter backend is only run if BINCAML_BNFC_TREESITTER +; is set to true, and it is false by default. this lets us use +; upstream bnfc for the main ocaml generation. (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) - (enabled_if %{bin-available:bnfc}) + (enabled_if %{env:BINCAML_BNFC_TREESITTER=false}) (action (progn (copy %{deps} basilir.cf) From ea6f12bbc58347cc32c8a91f9280f9c27f829e8c Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 13:08:05 +1000 Subject: [PATCH 2/7] fm --- tree-sitter/dune | 1 + 1 file changed, 1 insertion(+) diff --git a/tree-sitter/dune b/tree-sitter/dune index dc2376e7..d61ef069 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -13,6 +13,7 @@ ; bnfc tree-sitter backend is only run if BINCAML_BNFC_TREESITTER ; is set to true, and it is false by default. this lets us use ; upstream bnfc for the main ocaml generation. + (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) From aa4b7fec73d01b912ebd69b6cfccafb6044ee921 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 13:41:22 +1000 Subject: [PATCH 3/7] do clever things with detecting --tree-sitter --- lib/fe/dune | 6 ++++++ tree-sitter/.gitignore | 2 ++ tree-sitter/dune | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index 9771b1ac..bbbf26ad 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -45,3 +45,9 @@ (flags (:standard -open BasilIR)) (libraries bincaml.basilir)) + +(rule + (deps (universe)) + (action + (with-stdout-to tree-sitter-available + (bash "if bnfc --help | grep -q -- --tree-sitter; then printf true; else printf false; fi")))) diff --git a/tree-sitter/.gitignore b/tree-sitter/.gitignore index b73cc51b..869c50dd 100644 --- a/tree-sitter/.gitignore +++ b/tree-sitter/.gitignore @@ -1,3 +1,5 @@ +grammar.js.new + # Rust artifacts target/ diff --git a/tree-sitter/dune b/tree-sitter/dune index d61ef069..f5fc3da7 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -13,11 +13,10 @@ ; bnfc tree-sitter backend is only run if BINCAML_BNFC_TREESITTER ; is set to true, and it is false by default. this lets us use ; upstream bnfc for the main ocaml generation. - (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) - (enabled_if %{env:BINCAML_BNFC_TREESITTER=false}) + (enabled_if %{read:../lib/fe/tree-sitter-available}) (action (progn (copy %{deps} basilir.cf) @@ -29,3 +28,12 @@ basilir.cf --makefile) (diff? grammar.js tree-sitter-basilir/grammar.js)))) + +(rule + (alias runtest) + (deps (universe)) + (enabled_if (not %{read:../lib/fe/tree-sitter-available})) + (action + (echo + "tree-sitter/dune: bnfc tree-sitter generation skipped," + "because the installed bnfc doesn't support it.\n"))) From 788b97e811e4a2e6a7ce90b2f885bb3f6779f309 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 13:51:10 +1000 Subject: [PATCH 4/7] very clever --- lib/fe/dune | 15 ++++++++++++--- tree-sitter/dune | 10 +++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index bbbf26ad..2e03264f 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -47,7 +47,16 @@ (libraries bincaml.basilir)) (rule - (deps (universe)) + (target has-bnfc-tree-sitter) + (enabled_if (not %{bin-available:bnfc})) + (action (with-stdout-to %{target} (echo "false")))) + +(rule + (target has-bnfc-tree-sitter) + (enabled_if %{bin-available:bnfc}) + (deps %{bin:bnfc}) (action - (with-stdout-to tree-sitter-available - (bash "if bnfc --help | grep -q -- --tree-sitter; then printf true; else printf false; fi")))) + (with-stdout-to %{target} + (bash "bnfc --help | { if grep -q -- --tree-sitter; then printf true; else printf false; fi }")))) +; bash pipe structure is so that if `bnfc` exits with an error, we report that error and fail. +; "false" is only written if bnfc succeeds but tree-sitter was not found. diff --git a/tree-sitter/dune b/tree-sitter/dune index f5fc3da7..80e1e885 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -10,13 +10,13 @@ ; check that grammar.js is up to date. ; requires `bnfc-treesitter` from pac-nix. -; bnfc tree-sitter backend is only run if BINCAML_BNFC_TREESITTER -; is set to true, and it is false by default. this lets us use -; upstream bnfc for the main ocaml generation. +; bnfc tree-sitter backend is only run if tree-sitter is detected +; in the output of bnfc --help. this lets us use upstream bnfc +; for the main ocaml generation. (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) - (enabled_if %{read:../lib/fe/tree-sitter-available}) + (enabled_if %{read:../lib/fe/has-bnfc-tree-sitter}) (action (progn (copy %{deps} basilir.cf) @@ -32,7 +32,7 @@ (rule (alias runtest) (deps (universe)) - (enabled_if (not %{read:../lib/fe/tree-sitter-available})) + (enabled_if (not %{read:../lib/fe/has-bnfc-tree-sitter})) (action (echo "tree-sitter/dune: bnfc tree-sitter generation skipped," From 5987da9f2d0fea81e49567ef2bf4c7ab54e3c890 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 13:57:14 +1000 Subject: [PATCH 5/7] fmt --- lib/fe/dune | 15 +++++++++++---- tree-sitter/dune | 8 +++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index 2e03264f..ab7ac3dc 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -48,15 +48,22 @@ (rule (target has-bnfc-tree-sitter) - (enabled_if (not %{bin-available:bnfc})) - (action (with-stdout-to %{target} (echo "false")))) + (enabled_if + (not %{bin-available:bnfc})) + (action + (with-stdout-to + %{target} + (echo "false")))) (rule (target has-bnfc-tree-sitter) (enabled_if %{bin-available:bnfc}) (deps %{bin:bnfc}) (action - (with-stdout-to %{target} - (bash "bnfc --help | { if grep -q -- --tree-sitter; then printf true; else printf false; fi }")))) + (with-stdout-to + %{target} + (bash + "bnfc --help | { if grep -q -- --tree-sitter; then printf true; else printf false; fi }")))) + ; bash pipe structure is so that if `bnfc` exits with an error, we report that error and fail. ; "false" is only written if bnfc succeeds but tree-sitter was not found. diff --git a/tree-sitter/dune b/tree-sitter/dune index 80e1e885..0c0fdcf6 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -13,6 +13,7 @@ ; bnfc tree-sitter backend is only run if tree-sitter is detected ; in the output of bnfc --help. this lets us use upstream bnfc ; for the main ocaml generation. + (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) @@ -32,8 +33,9 @@ (rule (alias runtest) (deps (universe)) - (enabled_if (not %{read:../lib/fe/has-bnfc-tree-sitter})) + (enabled_if + (not %{read:../lib/fe/has-bnfc-tree-sitter})) (action (echo - "tree-sitter/dune: bnfc tree-sitter generation skipped," - "because the installed bnfc doesn't support it.\n"))) + "tree-sitter/dune: bnfc tree-sitter generation skipped," + "because the installed bnfc doesn't support it.\n"))) From e5c05864a7bf372b85217b3a976c8f0361f02556 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 14:05:56 +1000 Subject: [PATCH 6/7] use dune pipeline --- lib/fe/dune | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index ab7ac3dc..f79cb8a6 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -58,12 +58,13 @@ (rule (target has-bnfc-tree-sitter) (enabled_if %{bin-available:bnfc}) - (deps %{bin:bnfc}) (action (with-stdout-to %{target} - (bash - "bnfc --help | { if grep -q -- --tree-sitter; then printf true; else printf false; fi }")))) + (pipe-stdout + (run bnfc --help) + (bash + "if grep -q -- --tree-sitter; then printf true; else printf false; fi"))))) -; bash pipe structure is so that if `bnfc` exits with an error, we report that error and fail. +; if `bnfc` exits with an error, we report that error and fail. ; "false" is only written if bnfc succeeds but tree-sitter was not found. From ad922b8bb1ec4020cbc9e81dfd2acb582978e353 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 9 Mar 2026 14:10:39 +1000 Subject: [PATCH 7/7] we actually need to detect the specific tree-sitter fork --- lib/fe/dune | 2 +- tree-sitter/dune | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index f79cb8a6..ad596b62 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -64,7 +64,7 @@ (pipe-stdout (run bnfc --help) (bash - "if grep -q -- --tree-sitter; then printf true; else printf false; fi"))))) + "if grep -q -- --tree-sitter-word; then printf true; else printf false; fi"))))) ; if `bnfc` exits with an error, we report that error and fail. ; "false" is only written if bnfc succeeds but tree-sitter was not found. diff --git a/tree-sitter/dune b/tree-sitter/dune index 0c0fdcf6..e7ee71c3 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -10,9 +10,9 @@ ; check that grammar.js is up to date. ; requires `bnfc-treesitter` from pac-nix. -; bnfc tree-sitter backend is only run if tree-sitter is detected -; in the output of bnfc --help. this lets us use upstream bnfc -; for the main ocaml generation. +; bnfc tree-sitter backend is only run if the fixed tree-sitter fork is +; detected in the output of bnfc --help. this lets us use upstream +; bnfc for the main ocaml parser. (rule (alias runtest)