Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please support loading multiple objects #5

Open
jd-boyd opened this issue Oct 20, 2014 · 3 comments
Open

Please support loading multiple objects #5

jd-boyd opened this issue Oct 20, 2014 · 3 comments

Comments

@jd-boyd
Copy link
Owner

jd-boyd commented Oct 20, 2014

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?

@brando90
Copy link

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)

@lenianiva
Copy link

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

@jd-boyd
Copy link
Owner Author

jd-boyd commented Jun 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants