aboutsummaryrefslogtreecommitdiff
path: root/ocaml/reader.ml
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2015-01-25 23:30:37 -0500
committerChouser <chouser@n01se.net>2015-01-30 12:54:42 -0500
commita878f3bb778513c0cc8bbeb1a8ff61664e43de29 (patch)
tree9024de3b223d78abef619c4ee36316c24f4bee19 /ocaml/reader.ml
parentb7ffcab96166f15d6203551ffbc487da5076f92e (diff)
downloadmal-a878f3bb778513c0cc8bbeb1a8ff61664e43de29.tar.gz
mal-a878f3bb778513c0cc8bbeb1a8ff61664e43de29.zip
Ocaml: Use a real map type
T.Map is now a real OCaml binary-tree map, and supports arbitrary mal value types for both keys and values. Metadata support is provided in the data objects, but not yet in the printer, reader, or core library.
Diffstat (limited to 'ocaml/reader.ml')
-rw-r--r--ocaml/reader.ml26
1 files changed, 15 insertions, 11 deletions
diff --git a/ocaml/reader.ml b/ocaml/reader.ml
index c452e05..6827597 100644
--- a/ocaml/reader.ml
+++ b/ocaml/reader.ml
@@ -1,3 +1,6 @@
+module T = Types.Types
+ (* ^file ^module *)
+
let find_re re str =
List.map (function | Str.Delim x -> x | Str.Text x -> "impossible!")
(List.filter (function | Str.Delim x -> true | Str.Text x -> false)
@@ -17,17 +20,17 @@ type list_reader = {
let read_atom token =
match token with
- | "nil" -> Types.Nil
- | "true" -> Types.Bool true
- | "false" -> Types.Bool false
+ | "nil" -> T.Nil
+ | "true" -> T.Bool true
+ | "false" -> T.Bool false
| _ ->
match token.[0] with
- | '0'..'9' -> Types.Int (int_of_string token)
- | '"' -> Types.String (Str.global_replace (Str.regexp "\\\\\\(.\\)")
+ | '0'..'9' -> T.Int (int_of_string token)
+ | '"' -> T.String (Str.global_replace (Str.regexp "\\\\\\(.\\)")
"\\1"
(String.sub token 1 ((String.length token) - 2)))
- | ':' -> Types.Keyword (Str.replace_first (Str.regexp "^:") "" token)
- | _ -> Types.Symbol token
+ | ':' -> T.Keyword (Str.replace_first (Str.regexp "^:") "" token)
+ | _ -> Types.symbol token
let rec read_list list_reader =
match list_reader.tokens with
@@ -43,7 +46,7 @@ let rec read_list list_reader =
tokens = reader.tokens}
and read_quote sym tokens =
let reader = read_form tokens in
- {form = Types.List [ Types.Symbol sym; reader.form ];
+ {form = Types.list [ Types.symbol sym; reader.form ];
tokens = reader.tokens}
and read_form all_tokens =
match all_tokens with
@@ -54,17 +57,18 @@ and read_form all_tokens =
| "`" -> read_quote "quasiquote" tokens
| "~" -> read_quote "unquote" tokens
| "~@" -> read_quote "splice-unquote" tokens
+ | "@" -> read_quote "deref" tokens
| "(" -> let list_reader =
read_list {list_form = []; tokens = tokens} in
- {form = Types.List list_reader.list_form;
+ {form = Types.list list_reader.list_form;
tokens = list_reader.tokens}
| "{" -> let list_reader =
read_list {list_form = []; tokens = tokens} in
- {form = Types.Map list_reader.list_form;
+ {form = Types.list_into_map Types.MalMap.empty list_reader.list_form;
tokens = list_reader.tokens}
| "[" -> let list_reader =
read_list {list_form = []; tokens = tokens} in
- {form = Types.Vector list_reader.list_form;
+ {form = Types.vector list_reader.list_form;
tokens = list_reader.tokens}
| _ -> {form = read_atom token; tokens = tokens}