sexpdata icon indicating copy to clipboard operation
sexpdata copied to clipboard

Please support loading multiple objects

Open jd-boyd opened this issue 10 years ago • 3 comments

I would like to be able to load a file like this:

(define (a b c) 5)

(define (d e f) (+ e f))

When I try, I get:

  File "/home/jdboyd/.virtualenvs/pypile/lib/python3.3/site-packages/sexpdata.py", line 244, in loads
    assert len(obj) == 1  # FIXME: raise an appropriate error
AssertionError

I don't think there is an appropriate error to raise there since I think it should be able to parse that file.

If I patch the code to also export the parse function, I can get the above example file returned as a list like:

[[Symbol('define'), [Symbol('a'), Symbol('b'), Symbol('c')], 5], [Symbol('define'), [Symbol('d'), Symbol('e'), Symbol('f')], [Symbol('+'), Symbol('e'), Symbol('f')]]]

This is more useful than the assert. If the assert is important to some users, perhaps it could only be triggered when a single_express kwarg is set?

jd-boyd avatar Oct 20 '14 05:10 jd-boyd

similar error, but I get it when I have one single string:

    sexp = '''
        (Answer 2
         (ObjList
          ((CoqGoal
            ((fg_goals
              (((name 4)
                (ty
                 (App
                  (Ind
                   (((Mutind (MPfile (DirPath ((Id Logic) (Id Init) (Id Coq))))
                      (DirPath ()) (Id eq))
                     0)
                    (Instance ())))
                  ((Ind
                    (((Mutind (MPfile (DirPath ((Id Datatypes) (Id Init) (Id Coq))))
                       (DirPath ()) (Id nat))
                      0)
                     (Instance ())))
                   (App
                    (Const
                     ((Constant (MPfile (DirPath ((Id Nat) (Id Init) (Id Coq))))
                       (DirPath ()) (Id add))
                      (Instance ())))
                    ((Construct
                      ((((Mutind
                          (MPfile (DirPath ((Id Datatypes) (Id Init) (Id Coq))))
                          (DirPath ()) (Id nat))
                         0)
                        1)
                       (Instance ())))
                     (Var (Id n))))
                   (Var (Id n)))))
                (hyp
                 ((((Id n)) ()
                   (Ind
                    (((Mutind (MPfile (DirPath ((Id Datatypes) (Id Init) (Id Coq))))
                       (DirPath ()) (Id nat))
                      0)
                     (Instance ())))))))))
             (bg_goals ()) (shelved_goals ()) (given_up_goals ()))))))
        (Answer 2 Completed)
    '''
    print(sexp)
    #print(sexp)
    psexp = loads(sexp)

brando90 avatar Mar 21 '19 16:03 brando90

Why not just do parse('(' + s + ')') and interpret the result as a list?

lenianiva avatar Jun 06 '23 23:06 lenianiva

Why not just do parse('(' + s + ')') and interpret the result as a list?

If that was implemented in this library, I think it would break existing users. It certainly could be done by users of this library in their own code.

jd-boyd avatar Jun 07 '23 05:06 jd-boyd