1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io kernel macros make multiline namespaces parser
4 present sequences strings splitting fry accessors ;
9 TUPLE: interpolate-var name ;
11 : (parse-interpolate) ( string -- )
13 "${" split1-slice [ >string , ] [
16 [ >string interpolate-var boa , ]
17 [ (parse-interpolate) ] bi*
22 : parse-interpolate ( string -- seq )
23 [ (parse-interpolate) ] { } make ;
25 : (interpolate) ( string quot -- quot' )
26 [ parse-interpolate ] dip '[
28 [ name>> @ '[ _ @ present write ] ]
31 ] map [ ] join ; inline
35 MACRO: interpolate ( string -- )
36 [ [ get ] ] (interpolate) ;
38 : interpolate-locals ( string -- quot )
39 [ search [ ] ] (interpolate) ;
42 "]I" parse-multiline-string
43 interpolate-locals over push-all ; parsing