durableOne / orgmunge

MIT License
75 stars 4 forks source link

Parsing breaks when no top-level heading is present #6

Closed ispringle closed 1 year ago

ispringle commented 1 year ago

I have been getting the following error when there is not a top-level heading:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/IPringle/git/hub/ispringle/orgmunge/orgmunge/__init__.py", line 15, in __init__
    metadata, initial_body, headings = p.parse(string, debug=debug)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object

Below are a few minimal, orgfile which will produce this above error:

#+TITLE: Test
This file is a test.

The error is because the parse method is returning None when there is no top-level heading. I was trying to figure out how come that is and what to do to resolve this, but I cannot make head or tail of this yacc/ply grammar.

Nalisarc commented 1 year ago

Weird! Lemme see if I can get this to happen on my copy. From there I can see about writing tests.

Nalisarc commented 1 year ago

Okay I was able to write a test for it. I'm gonna start looking through my books to see if I can fix it. Thank you!

ispringle commented 1 year ago

Thanks!

durableOne commented 1 year ago

Thank you for catching this. Please pull the latest commit and see if it fixes the issue.

crdoconnor commented 1 year ago

This is still happening for me:

* Calculation TODO 
** Input
3+4+5+6
** Evaluation
from orgmunge import Org

calcfile = Org("test.org")
calcfile.write("test.org")

And then the error above when reparsing it again as it puts two newlines at the top:


* Calculation TODO 
** Input
3+4+5+6
** Evaluation

Great library though. I'm looking forward to building a calculator on top of it.

If you'd like I can fork and write a pull request with a failing test for the above scenario.

Nalisarc commented 1 year ago

Interesting... If you have a failing test ready it would be greatly appreciated.

I'm excited to see any software you build on top of orgmunge! Have a great rest of your day/night!

crdoconnor commented 1 year ago

No problem: https://github.com/durableOne/orgmunge/pull/10

Really happy that this library exists.

durableOne commented 1 year ago

Thank you for providing a test case @crdoconnor, I got it to pass now. Please pull the changes and see if it works for you.

crdoconnor commented 1 year ago

Thanks a lot :)

durableOne commented 1 year ago

Great library though. I'm looking forward to building a calculator on top of it.

That was exactly my hope: that this would open the door for people to build other things on top of it.