Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix issue #1, add check for no stopchar between number and collection

  • Loading branch information...
commit c3b1b7011c49ac3fa5fc9f89a1b729af6289f47e 1 parent 7474162
@sunng87 authored
Showing with 11 additions and 2 deletions.
  1. +9 −1 clj.py
  2. +2 −1  tests/clj-test.py
View
10 clj.py
@@ -54,6 +54,8 @@ def __init__(self, fd):
self.fd = fd
self.value_stack = []
self.stop_chars = [" ", ",", "\n", "\r"]
+ self.coll_open_chars = ["#", "[", "{"]
+ self.extra_num_chars = ["-", "+", ".", "e", "E"]
self.terminator = None ## for collection type
def decode(self):
@@ -151,13 +153,19 @@ def __read_token(self):
elif t == "number":
buf = []
- while c is not self.terminator and c is not "" and c not in self.stop_chars:
+ while c.isdigit() or (c in self.extra_num_chars):
buf.append(c)
c = fd.read(1)
e = c
numstr = ''.join(buf)
v = number(numstr)
+ ## special case for
+ ## [23[12]]
+ ## this is a valid clojure form
+ if e in self.coll_open_chars:
+ fd.seek(-1, os.SEEK_CUR)
+
elif t == "keyword":
buf = [] ##skip the leading ":"
while c is not self.terminator and c is not "" and c not in self.stop_chars:
View
3  tests/clj-test.py
@@ -23,7 +23,8 @@ def setUp(self):
"[1 2 3,4]": [1,2,3,4],
"{:a [1 2 3] :b #{23.1 43.1 33.1}}": {"a":[1,2,3], "b":set([23.1,43.1,33.1])},
"{:a 1 :b [32 32 43] :c 4}": {"a":1,"b":[32,32,43],"c":4},
- "\\": ""}
+ "\\": "",
+ "[23[34][32][4]]": [23,[34],[32],[4]]}
def test_all_data(self):
for k,v in self.data.items():
Please sign in to comment.
Something went wrong with that request. Please try again.