Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ocamlyacc with cpspg #165

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 3 additions & 8 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 5.1.1
- run: opam install dune
- run: opam exec -- dune build
- run: opam exec -- dune install
- run: eval $(opam env) && ./test.sh dbl ./test/test_suite

- name: Install Nix
uses: cachix/install-nix-action@v17
- run: nix shell . --command ./test.sh dbl ./test/test_suite
267 changes: 267 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
inputs = {
opam-nix.url = "github:tweag/opam-nix";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.follows = "opam-nix/nixpkgs";
cpspg.url = "github:adampsz/cpspg";
cpspg.inputs.opam-nix.follows = "opam-nix";
};
outputs = { self, flake-utils, opam-nix, nixpkgs, cpspg }@inputs:
let package = "dbl";
in flake-utils.lib.eachSystem ["x86_64-linux"] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
on = opam-nix.lib.${system};
scope =
on.buildDuneProject { } package ./. { ocaml-system = "*"; };
overlay = final: prev:
{
${package} = prev.${package}.overrideAttrs
(oa: { nativeBuildInputs = oa.nativeBuildInputs ++ [ cpspg.packages.${system}.default ]; });
};
in rec {
legacyPackages = scope.overrideScope overlay;

packages.default = self.legacyPackages.${system}.${package};
devShells.default = with pkgs; pkgs.mkShell {
buildInputs = [
cpspg.packages.${system}.default
# Source file formatting
nixpkgs-fmt
ocamlformat
# For `dune build --watch ...`
fswatch
# For `dune build @doc`
ocamlPackages.odoc
# OCaml editor support
ocamlPackages.ocaml-lsp
# Nicely formatted types on hover
ocamlPackages.ocamlformat-rpc-lib
# Fancy REPL thing
ocamlPackages.utop
];
};
});
}
5 changes: 3 additions & 2 deletions src/DblParser/YaccParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ op
| op_80 { $1 }
| op_90 { $1 }
| op_100 { $1 }
;
;

/* ========================================================================= */

Expand Down Expand Up @@ -391,7 +391,7 @@ expr_90
;

// exp1 ** exp2
expr_100
expr_100
: expr_150 op_100 expr_100 { make (EBOp($1, $2, $3)) }
| expr_150 { $1 }
;
Expand All @@ -417,6 +417,7 @@ expr_select
: UID DOT expr_ctor { (NPName $1, $3) }
| UID DOT expr_300 { (NPName $1, $3) }
| UID DOT expr_select { let (p, e) = $3 in (NPSel($1, p), e) }
;

expr_250
: expr_300 { $1 }
Expand Down
7 changes: 6 additions & 1 deletion src/DblParser/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
(ocamlyacc (modules YaccParser))
(ocamllex (modules Lexer))
;(ocamlyacc (modules YaccParser));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this line instead of commenting it out? As discussed on the last meeting, we are going to use nice features of cpspg (which are not implemented yet), so I think in the near future, we will be incompatible with ocamlyacc.

(rule
(deps YaccParser.mly)
(targets YaccParser.ml YaccParser.mli)
(action (chdir %{workspace_root} (run cpspg --compat %{deps} %{targets}))))

(library
(name dblParser)
Expand Down
10 changes: 5 additions & 5 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash
if ! [ -n "$1" ] || ! [ -n "$2" ]; then
echo "USAGE: ./test.sh PROGRAM TEST_SUITE"
echo "USAGE: ./test.sh BINARY TEST_SUITE"
exit 1
fi

if ! dune build; then
exit 1
fi
# if ! dune build; then
# exit 1
# fi

export DBL_LIB="lib/"

TIMEOUT=1.0

binary="_build/default/src/$1.exe"
binary=$1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a minor problem with this change. When I run tests locally, I would like to use a version of dbl compiled from source on the active branch, not the one that is installed on my system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of an oversight on my part - in my dev environment, dbl in PATH is the one from _build/.... To be fair, you still can run ./test.sh ./_build/default/src/dbl.exe ./test/test_suite to test against your freshly built dbl, but I understand that the default workflow should probably remain unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restored most of the original behaviour of test.sh in my branch - when passed a relative path as PROGRAM it does what it used to do.

flags=""

RED='\033[0;31m'
Expand Down
Loading