]> gitweb.factorcode.org Git - factor.git/blob - basis/xmode/utilities/utilities.factor
Merge branch 'master' into regexp
[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 regexp ;
4 IN: xmode.utilities
5
6 : implies ( x y -- z ) [ not ] dip or ; inline
7
8 : map-find ( seq quot -- result elt )
9     [ f ] 2dip
10     '[ nip @ dup ] find
11     [ [ drop f ] unless ] dip ; inline
12
13 : tag-init-form ( spec -- quot )
14     {
15         { [ dup quotation? ] [ [ object get tag get ] prepose ] }
16         { [ dup length 2 = ] [
17             first2 '[
18                 tag get children>string
19                 _ [ execute ] when* object get _ execute
20             ]
21         ] }
22         { [ dup length 3 = ] [
23             first3 '[
24                 tag get _ attr
25                 _ [ execute ] when* object get _ execute
26             ]
27         ] }
28     } cond ;
29
30 : with-tag-initializer ( tag obj quot -- )
31     [ object set tag set ] prepose with-scope ; inline
32
33 MACRO: (init-from-tag) ( specs -- )
34     [ tag-init-form ] map concat [ ] like
35     [ with-tag-initializer ] curry ;
36
37 : init-from-tag ( tag tuple specs -- tuple )
38     over [ (init-from-tag) ] dip ; inline
39
40 : <?insensitive-regexp> ( string ? -- regexp )
41     "i" "" ? <optioned-regexp> ;