Code using interpolation can now compile
parent
c46f857671
commit
c581b67193
|
@ -53,3 +53,6 @@ IN: xml.interpolate.tests
|
|||
|
||||
[ "<x>3</x>" ] [ 3 [XML <x><-></x> XML] xml-chunk>string ] unit-test
|
||||
[ "<x></x>" ] [ f [XML <x><-></x> XML] xml-chunk>string ] unit-test
|
||||
|
||||
\ parse-def must-infer
|
||||
[ "" interpolate-chunk ] must-infer
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: xml xml.state kernel sequences fry assocs xml.data
|
||||
accessors strings make multiline parser namespaces macros
|
||||
sequences.deep generalizations locals words combinators
|
||||
sequences.deep generalizations words combinators
|
||||
math present arrays ;
|
||||
IN: xml.interpolate
|
||||
|
||||
|
@ -48,23 +48,23 @@ M: interpolated interpolate-item
|
|||
: interpolate-xml-doc ( table xml -- xml )
|
||||
(clone) [ interpolate-tag ] change-body ;
|
||||
|
||||
GENERIC# (each-interpolated) 1 ( item quot -- ) inline
|
||||
M: interpolated (each-interpolated) call ;
|
||||
M: tag (each-interpolated)
|
||||
swap attrs>> values
|
||||
[ interpolated? ] filter
|
||||
swap each ;
|
||||
M: xml (each-interpolated)
|
||||
[ body>> ] dip (each-interpolated) ;
|
||||
M: object (each-interpolated) 2drop ;
|
||||
: (each-interpolated) ( item quot: ( interpolated -- ) -- )
|
||||
{
|
||||
{ [ over interpolated? ] [ call ] }
|
||||
{ [ over tag? ] [
|
||||
[ attrs>> values [ interpolated? ] filter ] dip each
|
||||
] }
|
||||
{ [ over xml? ] [ [ body>> ] dip (each-interpolated) ] }
|
||||
[ 2drop ]
|
||||
} cond ; inline recursive
|
||||
|
||||
: each-interpolated ( xml quot -- )
|
||||
'[ _ (each-interpolated) ] deep-each ; inline
|
||||
|
||||
:: number<-> ( doc -- doc )
|
||||
0 :> n! doc [
|
||||
dup var>> [ n >>var n 1+ n! ] unless drop
|
||||
] each-interpolated doc ;
|
||||
: number<-> ( doc -- dup )
|
||||
0 over [
|
||||
dup var>> [ over >>var [ 1+ ] dip ] unless drop
|
||||
] each-interpolated drop ;
|
||||
|
||||
MACRO: interpolate-xml ( string -- doc )
|
||||
string>doc number<-> '[ _ interpolate-xml-doc ] ;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
! Copyright (C) 2005, 2006 Daniel Ehrenberg
|
||||
! Copyright (C) 2005, 2009 Daniel Ehrenberg
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: xml.tests
|
||||
USING: kernel xml tools.test io namespaces make sequences
|
||||
|
|
Loading…
Reference in New Issue