why3 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env bash
#
# DESCRIPTION: process files generated by Why3


## diagnostics

PRG="$(basename "$0")"

function usage()
{
  echo
  echo "Usage: isabelle $PRG [OPTIONS] WHY3_FILE"
  echo
  echo "  Options are:"
  echo "    -b           batch mode"
  echo "    -i NAME      interactive mode using interface NAME"
  echo
19
  echo "  Process files generated by Why3"
20 21 22 23 24 25 26 27 28 29 30
  exit 1
}


## utilities

function make_theory()
{
  BNAME=`basename "$1"`

  if [ ! -e "$1.thy" ]; then
31
    echo -e "theory $BNAME\nimports Why3\nbegin\n\nwhy3_open \"$BNAME.xml\"\n" > "$1.thy"
32 33
    sed \
      -e 's/<lemma name="\([^"]*\)"[^>]*>/why3_vc \1\n\n/g' \
34 35 36
      -e 's/<[^l][^>]*>//g' \
      "$1.xml" >> "$1.thy"
    echo -e "why3_end\n\nend" >> "$1.thy"
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  fi
}


## process command line

while getopts "bi:" OPT
do
  case "$OPT" in
    b)
      BATCH=true
      ;;
    i)
      INTERACTIVE=true
      INTERFACE="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done


## main

shift $(($OPTIND - 1))

64 65 66 67 68
if [ "$1" = "" ]; then
  usage
else
  NAME=`dirname "$1"`/`basename "$1" .xml`
fi
69 70

if [ "$BATCH" = true ]; then
71
  $ISABELLE_PROCESS -e "use_thy \"$NAME\";" -rq Why3
72 73
elif [ "$INTERACTIVE" = true ]; then
  make_theory "$NAME"
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
  case "$INTERFACE" in
    emacs)
      "$ISABELLE_TOOL" emacs -L Why3 "$NAME.thy"
      ;;
    jedit)
      "$ISABELLE_TOOL" jedit -l Why3 "$NAME.thy"
      ;;
    jedit-server)
      if [ -f "$JEDIT_SETTINGS/server-Why3" ]; then
        "$ISABELLE_TOOL" jedit -j-server=server-Why3 -l Pure "$NAME.thy"
      else
        "$ISABELLE_TOOL" jedit -j-server=server-Why3 -l Why3 "$NAME.thy" &
      fi
      ;;
  esac
89 90 91
else
  usage
fi