jd-boyd/sexpdata

input with balanced parens somehow stops parsing

Closed this issue · 6 comments

I have a HUGE file with s-expressions, but it seems that no matter if I use load or loads, the input file is printed to my Python terminal (interactive terminal).

Python automatically prints the result of an expression; you need to assign it to a variable to avoid printing it to the screen.

Actually I traced it to an Exception.
On May 19, 2015 12:17 PM, "Ryan Gonzalez" notifications@github.com wrote:

Python automatically prints the result of an expression; you need to
assign it to a variable to avoid printing it to the screen.


Reply to this email directly or view it on GitHub
#8 (comment).

What is the exact command you entered in the Python terminal?

import sexpdata
with open('theFile.dcf', 'r') as dcfFile:
    dcf_text = dcfFile.read()

dcf_obj = sexpdata.loads(dcf_text)

And the code is hitting this Exception (i is 356220, len(self.string) is 14012331)

def parse(self):
    (i, sexp) = self.parse_sexp(0)
    if i < len(self.string):
        raise ExpectNothing(self.string[i:])
    return sexp

parens are balanced, but I think something with quotes in the data is messing up the parser and breaking out of the recursion in parse_sexp.... to attempt to debug I changed the function definition to def parse_sexp(self, i, level=0): and added to the recursive calls level+1 and indeed the level is 0 when the parser stops. (but it should be level 3 I think). I'm trying to reproduce the problem with a file that isn't 13Mb... but it's not going quickly.

If you can share a file that recreates the problem, even if it is 13Mb, I can probably track it down, but until then I think it might be best to close this.