(write-html | |||||||||||||||||||||||||||||||||||
'((html (head (title "My Title")) | |||||||||||||||||||||||||||||||||||
(body (@ (bgcolor "white")) | |||||||||||||||||||||||||||||||||||
(h1 "My Heading") | |||||||||||||||||||||||||||||||||||
(p "This is a paragraph.") | |||||||||||||||||||||||||||||||||||
(p "This is another paragraph.")))) | |||||||||||||||||||||||||||||||||||
(current-output-port)) Here is an example xexp from some guys homework assignment (http://web.cs.wpi.edu/~cs1102/a12/Assignments/Hwk7/html.html) (form ((action "http://localhost:8088/hello")) "What is your first name?" (input ((type "text") (name "firstName"))) (input ((type "submit") (value "Click Here"))))Here is the syntax for an xexp from xexp? in the reference:
And in this latter syntax, how is the attribute list distinguished from a list of embedded xexps? Is it due to the nesting in the attribute list? Another question, the racket manuals show xexp->string being used to generate html. Neil has a separate write-html function. Why the divergence? Thanks in advance! |
(cons symbol (list xexpr ...))
(list symbol xexpr ...)
(list symbol (list (list symbol string) ...) xexpr ...)
(define (xexpr->tok-tree an-xexpr)
(define (is-at-list e)
(and
(pair? e)
(pair? (car e))))
(cond
[(null? an-xexpr) an-xexpr]
[(not (pair? an-xexpr)) (tok-make 'tok:value `((value ,an-xexpr)))] ; actually diff toks for diff types
[else
(let(
[tag (car an-xexpr)]
[r1 (cdr an-xexpr)]
)
(cond
[(null? r1) an-xexpr]
[else
(let(
[first-element (car r1)]
[r2 (cdr r1)]
)
(cond
[(is-at-list first-element) (cons tag (cons first-element (map xexpr->tok-tree r2)))]
[else (cons tag (cons '() (map xexpr->tok-tree r1)))]
))]))]))
(define (test-xexpr-tok-tree-0)
(equal?
(xexpr->tok-tree
'(html (head (title "My Title"))
(body ((bgcolor "white"))
(h1 "My Heading")
(p ((style "default")) "This is a paragraph.")
(p "This is another paragraph."))))
'(html
()
(head () (title () (tok:value ((value "My Title")))))
(body
((bgcolor "white"))
(h1 () (tok:value ((value "My Heading"))))
(p ((style "default")) (tok:value ((value "This is a paragraph."))))
(p () (tok:value ((value "This is another paragraph.")))))
)))
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Great! thanks Neil!