Files
mercury/scripts/sicstus_conv.in
Fergus Henderson 04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00

72 lines
2.1 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! /bin/sh
# @configure_input@
#---------------------------------------------------------------------------#
# Copyright (C) 1995-1996 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#---------------------------------------------------------------------------#
#
# This sed script is used to convert from Mercury to Sicstus Prolog
# It does three things: delete the `:- module' line,
# expand backslash escapes, and replace the use
# of `^' for xor in calls to is/2 with `#'.
# The expansion of backslash escapes includes support for
# "\c" line continuation sequences, whereby the sequence
# backslash, "c", whitespace
# acts merely as layout text and is deleted from string literals;
# this allows string literals to extend over multiple lines, as in
# X = "foo\c
# bar".
# which is the same as X = "foobar".
# The commands for expanding \c are a bit complicated;
# here's an explanation.
#
# % this is the start of loop
# :l
# % if we see \c followed by any number of
# % spaces, tabs, or embedded newlines (\n), and then finally
# % followed by a non-embedded newline ($), we use the `N'
# % command to read in the next line; we then branch to
# % label `l' to start the loop again.
# /\\c\( * *\n*\)*$/{
# N
# b l
# }
# % at this point, we've read in all the lines of the \c
# % command, so we replace the \c followed by any number of
# % spaces, tabs, or embedded newlines (\n) with an empty
# % string.
# %
# /\\c\( * *\n*\)*/s///g
for file in "$@"; do
case $file in
*.m) base=`basename "$file" .m` ;;
*.nl) base=`basename "$file" .nl` ;;
*) base=`basename "$file"` ;;
esac
# see comments above for explanation of this `sed' command
sed -e '
/ is /s/\^/#/g
/^:- *module/d
/^[ ]*%/s/.*//
/\\\\/s//\\/g
/\\a/s///g
/\\b/s///g
/\\r/s//
/g
/\\f/s// /g
/\\t/s// /g
/\\n/s//\
/g
/\\v/s// /g
:l
/\\c\( * *\n*\)*$/{
N
b l
}
/\\c\( * *\n*\)*/s///g
' "$file" > "$base".pl
# see comments above for explanation of this `sed' command
done