diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-02 22:23:37 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-02 22:23:37 -0500 |
| commit | ea81a8087bcd7953b083a2be9db447f75e7ebf56 (patch) | |
| tree | 6cf47a2dbd55d42efc4a901eaabdec952f40ce89 /bash/reader.sh | |
| parent | 1617910ad342a55762f3ddabb975849d843cff85 (diff) | |
| download | mal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.tar.gz mal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.zip | |
All: split types into types, env, printer, core.
- types: low-level mapping to the implementation language.
- core: functions on types that are exposed directly to mal.
- printer: implementation called by pr-str, str, prn, println.
- env: the environment implementation
- Also, unindent all TCO while loops so that the diff of step4 and
step5 are minimized.
Diffstat (limited to 'bash/reader.sh')
| -rw-r--r-- | bash/reader.sh | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/bash/reader.sh b/bash/reader.sh index bc32fa7..585b152 100644 --- a/bash/reader.sh +++ b/bash/reader.sh @@ -2,20 +2,23 @@ # mal (Make Lisp) Parser/Reader # +if [ -z "${__mal_readerr_included__}" ]; then +__mal_readerr_included=true + source $(dirname $0)/types.sh READ_ATOM () { local token=${__reader_tokens[${__reader_idx}]} __reader_idx=$(( __reader_idx + 1 )) case "${token}" in - [0-9]*) number "${token}" ;; + [0-9]*) _number "${token}" ;; \"*) token="${token:1:-1}" token="${token//\\\"/\"}" - string "${token}" ;; + _string "${token}" ;; nil) r="${__nil}" ;; true) r="${__true}" ;; false) r="${__false}" ;; - *) symbol "${token}" ;; + *) _symbol "${token}" ;; esac } @@ -54,39 +57,39 @@ READ_FORM () { local token=${__reader_tokens[${__reader_idx}]} case "${token}" in \') __reader_idx=$(( __reader_idx + 1 )) - symbol quote; local q="${r}" + _symbol quote; local q="${r}" READ_FORM; local f="${r}" - list "${q}" "${f}" ;; + _list "${q}" "${f}" ;; \`) __reader_idx=$(( __reader_idx + 1 )) - symbol quasiquote; local q="${r}" + _symbol quasiquote; local q="${r}" READ_FORM; local f="${r}" - list "${q}" "${f}" ;; + _list "${q}" "${f}" ;; \~) __reader_idx=$(( __reader_idx + 1 )) - symbol unquote; local q="${r}" + _symbol unquote; local q="${r}" READ_FORM; local f="${r}" - list "${q}" "${f}" ;; + _list "${q}" "${f}" ;; \~\@) __reader_idx=$(( __reader_idx + 1 )) - symbol splice-unquote; local q="${r}" + _symbol splice-unquote; local q="${r}" READ_FORM; local f="${r}" - list "${q}" "${f}" ;; + _list "${q}" "${f}" ;; ^) __reader_idx=$(( __reader_idx + 1 )) - symbol with-meta; local wm="${r}" + _symbol with-meta; local wm="${r}" READ_FORM; local meta="${r}" READ_FORM; local obj="${r}" - list "${wm}" "${obj}" "${meta}" ;; + _list "${wm}" "${obj}" "${meta}" ;; @) __reader_idx=$(( __reader_idx + 1 )) - symbol deref; local d="${r}" + _symbol deref; local d="${r}" READ_FORM; local f="${r}" - list "${d}" "${f}" ;; + _list "${d}" "${f}" ;; \)) _error "unexpected ')'" ;; \() READ_SEQ "(" ")" - list ${r} ;; + _list ${r} ;; \]) _error "unexpected ']'" ;; \[) READ_SEQ "[" "]" - vector ${r} ;; + _vector ${r} ;; \}) _error "unexpected '}'" ;; \{) READ_SEQ "{" "}" - hash_map ${r} ;; + _hash_map ${r} ;; *) READ_ATOM esac } @@ -151,3 +154,5 @@ READLINE () { history -s -- "${r}" history -a "${READLINE_HISTORY_FILE}" } + +fi |
