Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/usr/bin/env nix-shell
  2. #!nix-shell -i bash -p bash -p lr -p pandoc
  3.  
  4. set -euo pipefail
  5.  
  6. preludeDir="${1:?dir please}"
  7.  
  8. # each file (except package.dhall) starts with a multiline-comment with markdown docstrings.
  9. # {- maybe docstring
  10. # docstring
  11. # maybe docstring -}
  12. parseDocstringForFile () {
  13. local doc=$(sed -n \
  14. -e '/^{-/,/-}$/ p' \
  15. "$1" \
  16. | sed -e '1s/^{-\s*//' \
  17. | sed -e '$s/\s*-}$//')
  18. if [ "$doc" = "" ]; then
  19. printf 'WARNING: %s has no docstring\n' "$1" >&2
  20. fi
  21. printf '%s' "$doc"
  22. }
  23.  
  24.  
  25. tmp=$(mktemp -d)
  26.  
  27. for file in $(lr -t "type = f" -s "$preludeDir" "$preludeDir"); do
  28. # those are the export files
  29. if [ "$(basename "$file")" = "package.dhall" ]; then
  30. continue
  31. fi
  32. # printf '%s\n' "$tmp/$file"
  33. echo "## $file"
  34. echo
  35. parseDocstringForFile "$preludeDir/$file"
  36. echo
  37. # TODO: build helper dhall executable that can print
  38. # the type of expressions while caching all imports.
  39. # (use dhall-flycheck code for that)
  40. echo
  41. echo "### Type"
  42. echo '```'
  43. (
  44. # don’t use the cache to preserve variable names
  45. export XDG_CACHE_HOME=/var/empty
  46. printf '(./%spackage.dhall).%s\n' "$preludeDir" "${file/\//.}" \
  47. | dhall resolve \
  48. | dhall type
  49. )
  50. echo '```'
  51. echo
  52. echo "<hr>"
  53. done | pandoc --standalone --to=html5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement