From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: [RFC] [PATCH] [babel] read description lists as lists of lists Date: Sun, 28 Sep 2014 12:49:23 +0200 Message-ID: <877g0ot3yk.fsf@gmail.com> References: <87ha03qv19.fsf@gmail.com> <87ha02a4qg.fsf@nicolasgoaziou.fr> <87d2anougv.fsf@gmail.com> <87tx3weqrv.fsf@nicolasgoaziou.fr> <87oau4my5o.fsf@gmail.com> <877g0qeosp.fsf@nicolasgoaziou.fr> <87tx3sl254.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYC36-0001BO-0s for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 06:49:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYC2y-00048m-Ga for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 06:49:51 -0400 Received: from plane.gmane.org ([80.91.229.3]:40421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYC2y-00047P-At for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 06:49:44 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XYC2s-00009B-Ef for emacs-orgmode@gnu.org; Sun, 28 Sep 2014 12:49:38 +0200 Received: from g231110213.adsl.alicedsl.de ([92.231.110.213]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Sep 2014 12:49:38 +0200 Received: from tjolitz by g231110213.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Sep 2014 12:49:38 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Aaron Ecay writes: Hi Aaron, > So the question is, how to provide a consistent language-agnostic view > of org structure to other languages. well, that would be the parse-tree normally, its a nested list containing all info about org structure. I tried to make two Lisps talk to each other (Emacs Lisp and PicoLisp), and initially thought it would be easy - just send lists back and forth. But when these lists are parse-trees produced by the Org parser framework, its not that straight-forward anymore, because these lists are send as strings and then read again by the other side, and there are lots of peculiarities in the string representation of Org parse-trees that make other languages choke, even if they otherwise understand lists very well. As an example, this nested list representation of this "created" headline is simple enough, PicoLisp can read it "as-is": #+NAME: hl1 #+BEGIN_SRC emacs-lisp :results verbatim (org-dp-create 'headline "Hallo World" 'data '(:name "foo") :level 2 :title "2nd level" :todo-keyword "NEXT" :tags '("office") :priority ?B) #+END_SRC #+results: hl1 : (headline (:level 2 :title "2nd level" :todo-keyword "NEXT" :tags ("office") :priority 66 :name "foo") (section nil "Hallo World")) #+BEGIN_SRC emacs-lisp :var lst=hl1 (length lst) #+END_SRC #+results: : 131 #+BEGIN_SRC picolisp :var lst=hl1 :results pp (in NIL (length lst)) #+END_SRC #+results: : 131 #+BEGIN_SRC picolisp :var lst=hl1 :results pp (in NIL (last (car (str lst)))) #+END_SRC #+results: : (section nil "Hallo World") So this can be read by PicoLisp (and probably many other list processing languages), except that nil is not NIL in PicoLisp. But when parsing this Org buffer its easy to see that syntax and semantics of Emacs Lisp circular lists as well as of strings with text-properties cannot easily be consumed by other languages (expecially when # is their comment-start character). Some post-processing is necessary, e.g. suppressing text properties, nil -> NIL, \n -> ^J, ^ -> \^, # -> \# etc., and I doubt this can be done in a language agnostic way. And then the circular relationships needs to be resolved to something the target language can understand... #+BEGIN_SRC emacs-lisp :results pp (org-element-parse-buffer) #+END_SRC #+results: (org-data nil (headline (:raw-value "--text follows this line--" :begin 1 :end 17295 :pre-blank 0 :contents-begin 30 :contents-end 17295 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1 :title (#("--text follows this line--" 0 26 (:parent #1))) :parent #0) [...cut...] (paragraph (:begin 17274 :end 17295 :contents-begin 17274 :contents-end 17295 :post-blank 0 :post-affiliated 17274 :parent #3) #("-- \ncheers,\nThorsten\n" 0 21 (:parent #4))))) -- cheers, Thorsten