* Normalized Parse-Tree readable by other Lisps (Languages)
@ 2013-09-15 16:38 Thorsten Jolitz
0 siblings, 0 replies; only message in thread
From: Thorsten Jolitz @ 2013-09-15 16:38 UTC (permalink / raw)
To: emacs-orgmode
Hi List,
I now got a first working version of code that transforms the parse-tree
produced by `org-element-parse-buffer' into a normalized form - in the
sense that special Emacs Lisp syntax is converted into plain standard
Lisp syntax:
The transformation steps can be seen in this code excerpt from the core
function
,---------------------------------------------------
| (defun iorg-normalize-parse-tree
| (&optional data buffer-or-file &rest args) ... )
`---------------------------------------------------
,--------------------------------------------------------------------
| [ ... ]
| ;; do the transformation
| (normalized-parse-tree-as-string
| (iorg--fix-read-syntax
| (iorg--tag-org-data-element
| (iorg--add-children-list
| (iorg--unwind-circular-list
| (iorg--tag-elems-with-id-attributes
| (if map?
| (org-element-map
| dat typ fun inf 1st-match no-recur with-affil)
| dat))))
| buf))))
| ;; upcase nil and t?
| (if preserve-nil-and-t-p
| normalized-parse-tree-as-string
| (iorg--nil-and-t-to-uppercase normalized-parse-tree-as-string))))
`--------------------------------------------------------------------
The parse-tree produced by `org-element-parse-buffer' is optionally
mapped first, then
1. each element is tagged with a :elem-id attribute
2. circular list references are unwind, i.e. ':parent #2#' becomes ':parent
2' (with parent having :elem-id 2)
3. in addition to its :parent attribute, each headline gets a :children
attribute (a list of sub-headlines)
4. the top 'org-data' element is tagged with meta-data and a unique ID,
making each parse-tree unique and easy to reference.
5. finally, other object references (#1=\"text\" and #1#) as well as read
syntax for text with properties (#(\"text\" 0 4 ...)) is fixed in the
sense that the three constructs are replaced by three functions:
- (hashtag '(\"text\" 0 4 ...))
- (hashtag-equal '(1 \"text\"))
- (enclosing-hashtag 1)
These should be defined as functions in the target language, e.g.
PicoLisp, and should produce the original Emacs Lisp read syntax when
evaluated.
6. as a last optional step, nil and t are upcased to NIL and T
I can now directly import an org parse-tree into PicoLisp after this
transformation, as a PicoLisp list, and start working on it.
Since PicoLisp is a pure and simple List, I would guess that the transformed
parse-tree can be read as-is by other Lisps too (untested), and maybe by
non-lisps that can read lists. The only remaining special syntax is ':keyword'.
Thereby one could avoid to write many Org-mode parsers for other Lisps
(languages), but rather use org-element (the de-facto specification of
Org-mode) for parsing and then import the transformed parse-tree as described.
The code is here, still under development:
[[https://github.com/tj64/iorg/blob/master/picoLisp/iorg/el/iorg.el][iorg.el]]
PS
I know I could have used ox.el for the transformation, but decided to
work directly on the parse-tree - for the good or for the bad, who
knows...
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-09-15 16:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-15 16:38 Normalized Parse-Tree readable by other Lisps (Languages) Thorsten Jolitz
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).