Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env nix-shell
- #!nix-shell -i bash -p bash -p lr -p pandoc
- set -euo pipefail
- preludeDir="${1:?dir please}"
- # each file (except package.dhall) starts with a multiline-comment with markdown docstrings.
- # {- maybe docstring
- # docstring
- # maybe docstring -}
- parseDocstringForFile () {
- local doc=$(sed -n \
- -e '/^{-/,/-}$/ p' \
- "$1" \
- | sed -e '1s/^{-\s*//' \
- | sed -e '$s/\s*-}$//')
- if [ "$doc" = "" ]; then
- printf 'WARNING: %s has no docstring\n' "$1" >&2
- fi
- printf '%s' "$doc"
- }
- tmp=$(mktemp -d)
- for file in $(lr -t "type = f" -s "$preludeDir" "$preludeDir"); do
- # those are the export files
- if [ "$(basename "$file")" = "package.dhall" ]; then
- continue
- fi
- # printf '%s\n' "$tmp/$file"
- echo "## $file"
- echo
- parseDocstringForFile "$preludeDir/$file"
- echo
- # TODO: build helper dhall executable that can print
- # the type of expressions while caching all imports.
- # (use dhall-flycheck code for that)
- echo
- echo "### Type"
- echo '```'
- (
- # donβt use the cache to preserve variable names
- export XDG_CACHE_HOME=/var/empty
- printf '(./%spackage.dhall).%s\n' "$preludeDir" "${file/\//.}" \
- | dhall resolve \
- | dhall type
- )
- echo '```'
- echo
- echo "<hr>"
- done | pandoc --standalone --to=html5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement