]> gitweb.factorcode.org Git - factor.git/blob - basis/xmode/utilities/utilities.factor
factor: trim using lists
[factor.git] / basis / xmode / utilities / utilities.factor
1 USING: combinators kernel namespaces quotations regexp sequences
2 xml.data xml.traversal ;
3 IN: xmode.utilities
4
5 : implies ( x y -- z ) [ not ] dip or ; inline
6
7 : tag-init-form ( spec -- quot )
8     {
9         { [ dup quotation? ] [ [ object get tag get ] prepose ] }
10         { [ dup length 2 = ] [
11             first2 '[
12                 tag get children>string
13                 _ [ execute ] when* object get _ execute
14             ]
15         ] }
16         { [ dup length 3 = ] [
17             first3 '[
18                 tag get _ attr
19                 _ [ execute ] when* object get _ execute
20             ]
21         ] }
22     } cond ;
23
24 : with-tag-initializer ( tag obj quot -- )
25     [ object set tag set ] prepose with-scope ; inline
26
27 MACRO: (init-from-tag) ( specs -- quot )
28     [ tag-init-form ] map concat [ ] like
29     [ with-tag-initializer ] curry ;
30
31 : init-from-tag ( tag tuple specs -- tuple )
32     over [ (init-from-tag) ] dip ; inline
33
34 : <?insensitive-regexp> ( string ? -- regexp )
35     "i" "" ? <optioned-regexp> ;