[retroforth] [ANN] RetroXMLWriter

  • From: Stefan Schmiedl <s@xxxxxx>
  • To: retroforth@xxxxxxxxxxxxx
  • Date: Sat, 16 Oct 2004 18:25:33 +0200

The attached file will become part of RetroWeb, but members
of this list get the first peek.
The new words allow to create a direct mapping between short
RetroForth words and XHTML tags. Example:

: (br)    s" br" (tag) ;    cr (br)
: (img)   s" img" (tag+) ;  cr " src='my.jpg'" (img)
: (title  s" title" (tag ;  cr (title ." hello world"  )
: (a      s" a" (tag+ ;     cr " href='#top'" (a ." jump to top" )

The parentheses are not negotiable, as the stack makes XHTML even
more similar to Lisp's s-expressions.

Feedback welcome.
s.

-- 
Stefan Schmiedl
+-------------------------------+----------------------------------------+
|Approximity GmbH               | EDV-Beratung Schmiedl                  |
|http://www.approximity.com     | Am Bräuweiher 4, 93499 Zandt, Germany  |
|mailto:stefan@xxxxxxxxxxxxxxx  | Tel. (09944) 3068-98, Fax -97          |
+-------------------------------+----------------------------------------+


-- Attached file included as plaintext by Ecartis --

20 constant #nesting
20 constant /tag
variable (stack)  /tag #nesting * allot
here variable, (tos)

: (push)  ( -- a )       (tos) @ /tag - dup (tos) ! ;
: (pop)   ( -- a )       (tos) @ dup /tag + (tos) ! ;
: $!      ( a # a' -- )  2dup c!  char+ swap cmove ;
: push    ( a # -- )     (push) $! ;
: pop     ( -- a # )     (pop) dup char+ swap c@ ;

: .<   '< emit ;
: .>   '> emit ;
: ./   '/ emit ;
: ./>  space ./ .> ;
: .</  .< ./ ;

: (tag)   ( a # -- )       .<  type ./> ;
: (tag+)  ( a' #' a # -- ) .<  type space type ./> ;

: (tag+ ( a' #' a # -- )   .<  2dup push type space type .> ;
: (tag  ( a # -- )         .< 2dup push type .> ;
: )     ( -- )             .</ pop type .> ;


| Testing

cr (tos) @ .
cr (push) . (tos) @ .     | /tag below, equal
cr (push) . (tos) @ .     | /tag below, equal
cr (pop) .  (tos) @ .     | /tag difference, increasing
cr (pop) .  (tos) @ .     | /tag difference, increasing
cr

| Samples

: (br)    s" br" (tag) ;    cr (br)
: (img)   s" img" (tag+) ;  cr " src='my.jpg'" (img)
: (title  s" title" (tag ;  cr (title ." hello world"  )
: (a      s" a" (tag+ ;     cr " href='#top'" (a ." jump to top" )


cr cr bye



Other related posts:

  • » [retroforth] [ANN] RetroXMLWriter