avakar / pycson

A Coffescript Object Notation (CSON) parser for Python 2 and Python 3.
Other
55 stars 7 forks source link

Serialized string not wrapped in quotes #6

Closed idleberg closed 8 years ago

idleberg commented 8 years ago

Consider the following example

import cson

scope = ".source.js"
key = "function()"

array = {}
array[key] = "function($1)"

atom = {scope: (array)}
result = cson.dumps(atom, sort_keys=True, indent=4)

print(result)

This will print invalid CSON, since the functon() key isn't wrapped in quotes:

'.source.js':
    function(): 'function($1)'

To validate the result, append cson.loads(result) to the example above. This produces the following error:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    cson.loads(result)
  File "/cson/parser.py", line 17, in loads
    return peg(s.replace('\r\n', '\n'), _p_root)
  File "/Library/Python/2.7/site-packages/speg/peg.py", line 24, in peg
    raise ParseError(err.msg, s, offset, err.line, err.col)
speg.peg.ParseError: ("expected ':', found u'(): '", 25, 2, 13)
avakar commented 8 years ago

Hi, thanks for the issue! It should be fixed in 0.6. Upgrade with pip install cson --upgrade.