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>3</x>" ] [ 3 [XML <x><-></x> XML] xml-chunk>string ] unit-test
|
||||||
[ "<x></x>" ] [ f [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.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: xml xml.state kernel sequences fry assocs xml.data
|
USING: xml xml.state kernel sequences fry assocs xml.data
|
||||||
accessors strings make multiline parser namespaces macros
|
accessors strings make multiline parser namespaces macros
|
||||||
sequences.deep generalizations locals words combinators
|
sequences.deep generalizations words combinators
|
||||||
math present arrays ;
|
math present arrays ;
|
||||||
IN: xml.interpolate
|
IN: xml.interpolate
|
||||||
|
|
||||||
|
@ -48,23 +48,23 @@ M: interpolated interpolate-item
|
||||||
: interpolate-xml-doc ( table xml -- xml )
|
: interpolate-xml-doc ( table xml -- xml )
|
||||||
(clone) [ interpolate-tag ] change-body ;
|
(clone) [ interpolate-tag ] change-body ;
|
||||||
|
|
||||||
GENERIC# (each-interpolated) 1 ( item quot -- ) inline
|
: (each-interpolated) ( item quot: ( interpolated -- ) -- )
|
||||||
M: interpolated (each-interpolated) call ;
|
{
|
||||||
M: tag (each-interpolated)
|
{ [ over interpolated? ] [ call ] }
|
||||||
swap attrs>> values
|
{ [ over tag? ] [
|
||||||
[ interpolated? ] filter
|
[ attrs>> values [ interpolated? ] filter ] dip each
|
||||||
swap each ;
|
] }
|
||||||
M: xml (each-interpolated)
|
{ [ over xml? ] [ [ body>> ] dip (each-interpolated) ] }
|
||||||
[ body>> ] dip (each-interpolated) ;
|
[ 2drop ]
|
||||||
M: object (each-interpolated) 2drop ;
|
} cond ; inline recursive
|
||||||
|
|
||||||
: each-interpolated ( xml quot -- )
|
: each-interpolated ( xml quot -- )
|
||||||
'[ _ (each-interpolated) ] deep-each ; inline
|
'[ _ (each-interpolated) ] deep-each ; inline
|
||||||
|
|
||||||
:: number<-> ( doc -- doc )
|
: number<-> ( doc -- dup )
|
||||||
0 :> n! doc [
|
0 over [
|
||||||
dup var>> [ n >>var n 1+ n! ] unless drop
|
dup var>> [ over >>var [ 1+ ] dip ] unless drop
|
||||||
] each-interpolated doc ;
|
] each-interpolated drop ;
|
||||||
|
|
||||||
MACRO: interpolate-xml ( string -- doc )
|
MACRO: interpolate-xml ( string -- doc )
|
||||||
string>doc number<-> '[ _ interpolate-xml-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.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: xml.tests
|
IN: xml.tests
|
||||||
USING: kernel xml tools.test io namespaces make sequences
|
USING: kernel xml tools.test io namespaces make sequences
|
||||||
|
|
Loading…
Reference in New Issue