Skip to content

Commit

Permalink
ocaml: fix negative numbers handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dubek committed Feb 26, 2016
1 parent 0901c8b commit 2c1eb1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ocaml/reader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ let read_atom token =
| _ ->
match token.[0] with
| '0'..'9' -> T.Int (int_of_string token)
| '-' -> (match String.length token with
| 1 -> Types.symbol token
| _ -> (match token.[1] with
| '0'..'9' -> T.Int (int_of_string token)
| _ -> Types.symbol token))
| '"' -> T.String (gsub (Str.regexp "\\\\.")
(function
| "\\n" -> "\n"
Expand Down
4 changes: 4 additions & 0 deletions tests/step1_read_print.mal
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ false
;=>7
7
;=>7
-123
;=>-123


;; Testing read of symbols
Expand Down Expand Up @@ -57,6 +59,8 @@ abc-def
;=>(* 1 2)
(** 1 2)
;=>(** 1 2)
(* -3 6)
;=>(* -3 6)

;; Test commas as whitespace
(1 2, 3,,,,),,
Expand Down
3 changes: 3 additions & 0 deletions tests/step2_eval.mal
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
(/ (- (+ 515 (* 222 311)) 302) 27)
;=>2565

(* -3 6)
;=>-18

(abc 1 2 3)
; .*\'abc\' not found.*

Expand Down

0 comments on commit 2c1eb1a

Please sign in to comment.