ormolu/default.nix
Utku Demir 7268eb1e98 Handle operator chains better
I implemented a custom logic where we assign a score to every occurance of
an operator based on their location, and the average of that score determine
the fixity of the operator.

As you can imagine, the solution is a bit brittle; and it is easy to mislead
it if you knowingly craft an input, but it gave acceptable results for every
code snippet I found online. And since it returns the same AST no matter how
we infer the fixities, it is not the end of the world if we infer something
incorrectly.

The code is not really optimised, and I think it has quadratic time
complexity. Notably, we use opTreeLoc function quite often and it traverses
the whole tree every time. Memoizing that on the OpBranch constructor would
make formatting files with reeeally long operator chains a lot faster. We
can do this once we decide to optimize for speed.
2019-09-10 18:27:15 +02:00

83 lines
1.8 KiB
Nix

{ pkgs ? (import ./nix/nixpkgs) }:
let
ormoluCompiler = "ghc865";
source = pkgs.lib.sourceByRegex ./.[
"^.*\.md$"
"^app.*$"
"^data.*$"
"^ormolu.cabal$"
"^src.*$"
"^tests.*$"
];
haskellPackages = pkgs.haskell.packages.${ormoluCompiler}.override {
overrides = ormoluOverlay;
};
ormoluOverlay = self: super: {
"ormolu" = super.callCabal2nix "ormolu" source { };
};
ormolize = import ./nix/ormolize {
inherit pkgs;
inherit haskellPackages;
};
ormolizedPackages = doCheck:
pkgs.lib.mapAttrs (_: v: ormolize { package = v; inherit doCheck; }) haskellPackages;
in {
ormolu = haskellPackages.ormolu;
ormoluShell = haskellPackages.shellFor {
packages = ps: [ ps.ormolu ];
buildInputs = [ haskellPackages.cabal-install haskellPackages.ghcid ];
};
inherit ormoluOverlay ormoluCompiler;
hackage = ormolizedPackages false;
hackageTests = with pkgs.lib; pkgs.recurseIntoAttrs (
let ps = [
"QuickCheck"
"ShellCheck"
"aeson"
"attoparsec"
"aws"
"cassava"
"conduit"
"cryptonite"
"diagrams-core"
"distributed-process"
"esqueleto"
"fay"
"haxl"
"hedgehog"
"hlint"
"megaparsec"
"ormolu"
"postgrest"
"servant"
"servant-server"
"tensorflow"
"text_1_2_4_0"
"tls"
"yesod-core"
# Comment idempotence issue
# "Agda"
# "brick"
# "hakyll"
# "hledger"
# "http-client"
# "idris"
# "intero"
# "leksah"
# "pandoc"
# "pipes"
# "stack"
# Missing language extension
# "lens" #fixed in master
# "purescript"
];
in listToAttrs (map (p: nameValuePair p (ormolizedPackages true).${p}) ps)
);
}