Last active
September 21, 2022 20:37
-
-
Save ramirez7/925c0ef38b24ebf64a5b50093669b455 to your computer and use it in GitHub Desktop.
parse-package-imports.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env bash | |
| set -euo pipefail | |
| shopt -s inherit_errexit | |
| packagesRaw=$(./parse-package-imports.sh $1) | |
| shift | |
| readarray -t foundPackages <<< "$packagesRaw" | |
| nix="haskellPackages.ghcWithPackages (pkgs: with pkgs; [ ${foundPackages[@]} ])" | |
| nix-shell -p "$nix" "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env bash | |
| set -euo pipefail | |
| shopt -s inherit_errexit | |
| file="$1" | |
| regex='^import[[:space:]]*"([A-Za-Z0-9-]+)"' | |
| while IFS= read -r line | |
| do | |
| if [[ $line =~ $regex ]] | |
| then | |
| echo "${BASH_REMATCH[1]}" | |
| fi | |
| done < "$file" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE PackageImports #-} | |
| module Whatever where | |
| import "puhoy" OI | |
| import "there" THERE | |
| import HMM | |
| import "lol" LOL | |
| x :: Int | |
| x = 2 | |
| s :: String | |
| s = "import \"hi\" HI" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE PackageImports #-} | |
| module Main where | |
| import "timeit" System.TimeIt | |
| main :: IO () | |
| main = timeIt $ putStrLn "puhoy there!" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to work:
Sanity check of the parser: