]> gitweb.factorcode.org Git - factor.git/blob - basis/xmode/utilities/utilities.factor
3fbce8e7cfbd0a5f90a1f4a66a73587307196c4b
[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 : tag-init-form ( spec -- quot )
9     {
10         { [ dup quotation? ] [ [ object get tag get ] prepose ] }
11         { [ dup length 2 = ] [
12             first2 '[
13                 tag get children>string
14                 _ [ execute ] when* object get _ execute
15             ]
16         ] }
17         { [ dup length 3 = ] [
18             first3 '[
19                 tag get _ attr
20                 _ [ execute ] when* object get _ execute
21             ]
22         ] }
23     } cond ;
24
25 : with-tag-initializer ( tag obj quot -- )
26     [ object set tag set ] prepose with-scope ; inline
27
28 MACRO: (init-from-tag) ( specs -- quot )
29     [ tag-init-form ] map concat [ ] like
30     [ with-tag-initializer ] curry ;
31
32 : init-from-tag ( tag tuple specs -- tuple )
33     over [ (init-from-tag) ] dip ; inline
34
35 : <?insensitive-regexp> ( string ? -- regexp )
36     "i" "" ? <optioned-regexp> ;