Skip to content

Instantly share code, notes, and snippets.

@ben-x9
Last active October 4, 2017 04:44
Show Gist options
  • Save ben-x9/02272b76bb2dd6490ca75d05cdecab03 to your computer and use it in GitHub Desktop.
Save ben-x9/02272b76bb2dd6490ca75d05cdecab03 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Works with merlin version 2.5.4. Using protocol described at
# https://github.com/ocaml/merlin/blob/master/doc/dev/OLD-PROTOCOL.md#type-checking
usage ()
{
echo
echo Generate a signature for a Bucklescript module.
echo
echo Run this script from the root directory of the project,
echo passing in the module name.
echo
echo e.g: sig My_module
echo
echo For Reason pipe the output to:
echo refmt --parse ml --print re --interface true
echo
echo 'e.g: sig MyModule | refmt --parse ml --print re --interface true'
echo
exit 1
}
[ -z "$1" ] && usage
mkdir -p ~/.tmp
it=~/.tmp/it
echo '["checkout","auto","."]["type","expression","'$1'","at","end"]' >$it
echo '["type","expression","'$1'","at","end"]' >>$it
ocamlmerlin <$it | sed -e '1d' -e '2d' -e 's/^\["return","sig *//' -e 's/ *end"\]$//' -e 's/\\"/"/g' -e 's/\\n/\
/g' | sed -e '/^ *$/d' -e 's/^ //'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment