aboutsummaryrefslogtreecommitdiff
path: root/bash/step1_read_print.sh
blob: 881c0c3ee775fc2d14e181fdfa41022929fd2a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env 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