aboutsummaryrefslogtreecommitdiff
path: root/ocaml/reader.ml
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2015-01-22 02:59:48 -0500
committerChouser <chouser@n01se.net>2015-01-30 12:54:42 -0500
commit921a951fe4d088e60ce25866344bd534420f9ec6 (patch)
tree411999aa4176c13e61f3cda4508f873f1f067975 /ocaml/reader.ml
parent59d10e1bd703f65e12fef85bceef4204f82685fb (diff)
downloadmal-921a951fe4d088e60ce25866344bd534420f9ec6.tar.gz
mal-921a951fe4d088e60ce25866344bd534420f9ec6.zip
Ocaml: Add step 2, nothing optional
Diffstat (limited to 'ocaml/reader.ml')
-rw-r--r--ocaml/reader.ml26
1 files changed, 12 insertions, 14 deletions
diff --git a/ocaml/reader.ml b/ocaml/reader.ml
index 51ab522..c32fa91 100644
--- a/ocaml/reader.ml
+++ b/ocaml/reader.ml
@@ -3,7 +3,7 @@ let find_re re str =
(List.filter (function | Str.Delim x -> true | Str.Text x -> false)
(Str.full_split re str)) ;;
-let token_re = (Str.regexp "~@\\|[][{}()'`~^@]\\|\"\\(\\\\.\\|[^\"]\\)*\"\\|;.*\\|[^][ \n{}('\"`,;)]*")
+let token_re = (Str.regexp "~@\\|[][{}()'`~^@]\\|\"\\(\\\\.\\|[^\"]\\)*\"\\|;.*\\|[^][ \n{}('\"`,;)]*")
type reader = {
form : Types.mal_type;
@@ -36,11 +36,11 @@ let rec read_list list_reader =
raise End_of_file;
| token :: tokens ->
if Str.string_match (Str.regexp "[])}]") token 0 then
- {list_form = list_reader.list_form; tokens = tokens}
+ {list_form = list_reader.list_form; tokens = tokens}
else
- let reader = read_form list_reader.tokens in
+ let reader = read_form list_reader.tokens in
read_list {list_form = list_reader.list_form @ [reader.form];
- tokens = reader.tokens}
+ tokens = reader.tokens}
and read_quote sym tokens =
let reader = read_form tokens in
{form = Types.MalList [ Types.Symbol sym; reader.form ];
@@ -50,17 +50,15 @@ and read_form all_tokens =
| [] -> raise End_of_file;
| token :: tokens ->
match token with
- | "'" -> read_quote "quote" tokens
- | "`" -> read_quote "quasiquote" tokens
- | "~" -> read_quote "unquote" tokens
+ | "'" -> read_quote "quote" tokens
+ | "`" -> read_quote "quasiquote" tokens
+ | "~" -> read_quote "unquote" tokens
| "~@" -> read_quote "splice-unquote" tokens
- | _ ->
- match token.[0] with
- | '[' | '(' | '{' -> let list_reader =
- read_list {list_form = []; tokens = tokens} in
- {form = Types.MalList list_reader.list_form;
- tokens = list_reader.tokens}
- | _ -> {form = read_atom token; tokens = tokens}
+ | "[" | "(" | "{" -> let list_reader =
+ read_list {list_form = []; tokens = tokens} in
+ {form = Types.MalList list_reader.list_form;
+ tokens = list_reader.tokens}
+ | _ -> {form = read_atom token; tokens = tokens}
let read_str str = (read_form (List.filter ((<>) "") (find_re token_re str))).form