1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/bash/step1_read_print.sh
2014-05-10 15:45:36 -05:00

44 lines
627 B
Bash
Executable File

#!/bin/bash
source $(dirname $0)/reader.sh
source $(dirname $0)/printer.sh
# read
READ () {
[ "${1}" ] && r="${1}" || READLINE
READ_STR "${r}"
}
# eval
EVAL () {
local ast="${1}"
local env="${2}"
r=
[[ "${__ERROR}" ]] && return 1
r="${ast}"
}
# print
PRINT () {
if [[ "${__ERROR}" ]]; then
_pr_str "${__ERROR}" yes
r="Error: ${r}"
__ERROR=
else
_pr_str "${1}" yes
fi
}
# repl
REP () {
READ "${1}"
EVAL "${r}"
PRINT "${r}"
}
# repl loop
while true; do
READLINE "user> " || exit "$?"
[[ "${r}" ]] && REP "${r}" && echo "${r}"
done