3/02/2008

I'm reimplementing an in-house script from scratch because the licence of the script is not able to be open. Although I wrote the original one in my own leisure time, recent version is more contributed by my office hour. Thus, I know the company owns that.

Anyway the original ideas have been laid down in my head. And my understandings of Scheme has grown from when I wrote the original one. Here's the outcome of this weekend, which was achieved cradling the baby.

cnvr.scm
latex.scm

You can use these modules with Gauche to define some rules to convert SXML data to LaTeX, or you like, as below.
(use cnvr)
(use latex)
(use sxml.sxpath)
(use sxml.tools)
(use text.tree)

(define-simple-rules make-latex-cmd
  bold item)

(define-simple-rules make-latex-env
  li)

(define-simple-rules through
  p top body)

(define-tag a
  (define-rule
    (lambda () '())
    (lambda (str) 
      (list str "<" ($@ 'val) ">\n"))
    (lambda () '())))

(define sxml 
  '(top 
     (body (p "first sentence\n" 
              (a (@ (val "20")) "the attr: "))
           (bold "emph this!")
           (li (item "first line")
               (item "second line")))))

(write-tree (cnvr sxml sxml))
The result is this:
first sentence
the attr: <20>
\bold{emph this!}
\begin{li}%
\item{first line}\item{second line}
\end{li}%
It has still a big problem with macro. Of course the problem is variable capturing. If you define a rule with certain name like "list", it overide the procedure "list". But I decided to expose it in as-is.

2 Comments:

Anonymous Anonymous said...

I think, that you are not right. I am assured. I can prove it. Write to me in PM, we will talk.

6:49 AM  
Anonymous Anonymous said...

I think, that you are not right. I am assured. I can defend the position. Write to me in PM, we will communicate.

3:13 PM  

Post a Comment

<< Home