rasendubi / uniorg

An accurate Org-mode parser for JavaScript/TypeScript
https://oleksii.shmalko.com/uniorg
GNU General Public License v3.0
256 stars 25 forks source link

feat: statistics-cookie #41

Closed vidbina closed 2 years ago

vidbina commented 2 years ago

This PR provides a rudimentary implementation for parsing statistics-cookies https://orgmode.org/worg/dev/org-syntax.html#Statistics_Cookies.

I'm thinking about extending this such that StatisticsCookie has a statistic field of the types null | PercentStat | FractionStat. @rasendubi, does this fit within the vision of the project or do you consider this a concern that end-users should handle in their own application logic?

vidbina commented 2 years ago
  1. Thanks for your work here! 🏆 I did a bit of sweating to debug my WIP as I started by populating contentsBegin and contentsEnd which I didn't realize would trigger parseObject calls on the content. Keeping org-element.el open alongside parser.ts was extremely helpful in figuring out that I had to set begin and end instead to avoid calling restrictionFor(o.type) with an empty result when type equals statistics-cookie. Really happy that you did the heavy lifting to make this available. 🥳

  2. Let me know if I've missed something and if you want me to update the README.md or if you'd like to do the honors (if the changes pass the quality check). I've looked at #33 and can't help to wonder if I've missed something. Scope of that change is much bigger since org-cite syntax is considerably more complex so maybe the delta between isn't something for me to worry about.

  3. What is your workflow in developing? I ran npm run dev and realized it didn't do much in my setup, so I ended up running npm run build and npm run test directly between my changes. Sometimes I would forget to rebuild between my test runs 🤦🏿‍♂ so any pro-tips as to how you keep your cycles brief would be helpful.

P.S.: I've spared you any of the package-lock.json changes. 🙊

codecov-commenter commented 2 years ago

Codecov Report

Merging #41 (2980b31) into master (e3a1724) will increase coverage by 0.03%. The diff coverage is 91.66%.

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   95.89%   95.92%   +0.03%     
==========================================
  Files          15       15              
  Lines        1606     1618      +12     
  Branches      528      520       -8     
==========================================
+ Hits         1540     1552      +12     
  Misses         65       65              
  Partials        1        1              
Impacted Files Coverage Δ
packages/uniorg-parse/src/parser.ts 95.22% <91.66%> (+0.05%) :arrow_up:

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

vidbina commented 2 years ago

As a note to future self, when developing or debugging features, it may help to compare the output of the Emacs parser. While writing the headline parser, I often used the following expression

((lambda (object) (with-temp-buffer
                    (insert object)
                    (kill-region (point-min) (point-max))))
 (prin1-to-string (with-temp-buffer
                    (save-excursion
                      (insert "* [1/0]Title"))
                    (org-element-headline-parser (point-max) nil))))

to produce the parsing output from org-element.el that I could drop in my notes to compare and contrast to what uniorg produces.

Thanks for making all the fixes in https://github.com/rasendubi/uniorg/commit/da79786f7c3afda29f8fb65052e09ca4fec6d4f3 so I no longer have to! 😅 Provides a good example of what I should keep on my radar for future work.

Your fixes now also provide a first explicit example of how to deal with postBlank handling which will become relevant for radio-targets and actually seems to be a thing for most org-element.el parser functions but must have been handled through a different mechanism in uniorg before -- now you've gifted us the idiomatic uniorg way of covering this.

rasendubi commented 2 years ago

There is the following function in parser.ts (in a comment) I use to compare uniorg/org-element output:

(defun rasen/org-debug ()
  "Show org AST for the current buffer."
  (interactive)
  (let ((document (org-element-parse-buffer)))
    (with-current-buffer-window "*org-elements*" nil nil
      (emacs-lisp-mode)
      (pp (cddr document)))))

Just open an org-mode buffer and call M-x rasen/org-debug and it shows the org-element AST.