#!/usr/bin/env bash
# TODO:
# - put the exercises from each chapter in their own module
# - replicate the imports from that module
# - import that module hiding anything defined in an exercise section
# This script can be used to automatically generate assignment files from PLFA source files.
# It takes a course abbreviation, e.g. TSPL, a year, and the number of the assignment.
# At the moment, it outputs the University of Edinburgh guidelines for good scholarly practice,
# making it somewhat specific to courses run there, but the header should be easy to edit.
#
# Usage:
#
# ./make_assignment.sh [COURSE_NAME] [COURSE_YEAR] [ASSIGNMENT_NUMBER] [PLFA_SOURCE_FILE...]
COURSE=""
YEAR=""
NUM=""
## Make assignment header
## Awk Scripts
AWK_GET_IMPORTS='
/^#/ {
import=0
}
/^## Imports/ {
import=1
}
/^```/ {
code=!code;
{
if (import)
print $0
};
next
}
{
if (import) {
if (code)
print " "$0
else
print $0
}
}
'
AWK_GET_DEFNS='
/^#/ {
exercise=0
}
/^#### Exercise/ {
exercise=1
}
/^```/ {
code=!code;
next
}
!/^ / {
postulate=0
}
/^postulate/ {
postulate=1
}
/^ [^ :(){}]+ +:/ {
if (exercise && code && postulate)
print $0
}
/^[^ :(){}]+ +:/ {
if (exercise && code)
print $0
}
'
AWK_GET_EXERCISES='
/^#/ {
exercise=0
}
/^#### Exercise/ {
exercise=1
}
/^```/ {
code=!code;
{
if (exercise)
print $0
};
next
}
{
if (exercise) {
if (code)
print " "$0
else
print $0
}
}
'
## Exercises
for; do
# Generate Section & Module Header
NAME=
# Extract Imports
# Generate Import and Hiding List
AGDA_MODULE=
HIDING_LIST=""
OLDIFS=
IFS=
for;
do
NEW=
if [; then
HIDING_LIST=""
else
HIDING_LIST="; "
fi
done
IFS=
# Extract Exercises
done