[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Normalized Parse-Tree readable by other Lisps (Languages)
From: |
Thorsten Jolitz |
Subject: |
[O] Normalized Parse-Tree readable by other Lisps (Languages) |
Date: |
Sun, 15 Sep 2013 18:38:44 +0200 |
User-agent: |
Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux) |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] Normalized Parse-Tree readable by other Lisps (Languages),
Thorsten Jolitz <=