]> gitweb.factorcode.org Git - factor.git/blob - basis/xmode/utilities/utilities.factor
Starting to switch xmode to regexp; getting rid of <TAGS
[factor.git] / basis / xmode / utilities / utilities.factor
1 USING: accessors sequences assocs kernel quotations namespaces
2 xml.data xml.traversal combinators macros parser lexer words fry ;
3 IN: xmode.utilities
4
5 : implies ( x y -- z ) [ not ] dip or ; inline
6
7 : map-find ( seq quot -- result elt )
8     [ f ] 2dip
9     '[ nip @ dup ] find
10     [ [ drop f ] unless ] dip ; inline
11
12 : tag-init-form ( spec -- quot )
13     {
14         { [ dup quotation? ] [ [ object get tag get ] prepose ] }
15         { [ dup length 2 = ] [
16             first2 '[
17                 tag get children>string
18                 _ [ execute ] when* object get _ execute
19             ]
20         ] }
21         { [ dup length 3 = ] [
22             first3 '[
23                 tag get _ attr
24                 _ [ execute ] when* object get _ execute
25             ]
26         ] }
27     } cond ;
28
29 : with-tag-initializer ( tag obj quot -- )
30     [ object set tag set ] prepose with-scope ; inline
31
32 MACRO: (init-from-tag) ( specs -- )
33     [ tag-init-form ] map concat [ ] like
34     [ with-tag-initializer ] curry ;
35
36 : init-from-tag ( tag tuple specs -- tuple )
37     over [ (init-from-tag) ] dip ; inline