Skip to content
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
23 changes: 23 additions & 0 deletions lib/fe/dune
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@
(flags
(:standard -open BasilIR))
(libraries bincaml.basilir))

(rule
(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})
(action
(with-stdout-to
%{target}
(pipe-stdout
(run bnfc --help)
(bash
"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.
2 changes: 2 additions & 0 deletions tree-sitter/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
grammar.js.new

# Rust artifacts
target/

Expand Down
16 changes: 15 additions & 1 deletion tree-sitter/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
; check that grammar.js is up to date.
; requires `bnfc-treesitter` from pac-nix.

; 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)
(deps %{project_root}/lib/fe/BasilIR.cf)
(enabled_if %{bin-available:bnfc})
(enabled_if %{read:../lib/fe/has-bnfc-tree-sitter})
(action
(progn
(copy %{deps} basilir.cf)
Expand All @@ -25,3 +29,13 @@
basilir.cf
--makefile)
(diff? grammar.js tree-sitter-basilir/grammar.js))))

(rule
(alias runtest)
(deps (universe))
(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")))
Loading