1 USING: sequences assocs kernel quotations namespaces xml.data
2 xml.utilities combinators macros parser words ;
5 : implies >r not r> or ; inline
7 : child-tags ( tag -- seq ) tag-children [ tag? ] filter ;
9 : map-find ( seq quot -- result elt )
11 [ nip ] swap [ dup ] 3compose find
12 >r [ drop f ] unless r> ; inline
14 : tag-init-form ( spec -- quot )
16 { [ dup quotation? ] [ [ object get tag get ] prepose ] }
17 { [ dup length 2 = ] [
19 >r >r tag get children>string
20 r> [ execute ] when* object get r> execute
23 { [ dup length 3 = ] [
26 r> [ execute ] when* object get r> execute
31 : with-tag-initializer ( tag obj quot -- )
32 [ object set tag set ] prepose with-scope ; inline
34 MACRO: (init-from-tag) ( specs -- )
35 [ tag-init-form ] map concat [ ] like
36 [ with-tag-initializer ] curry ;
38 : init-from-tag ( tag tuple specs -- tuple )
39 over >r (init-from-tag) r> ; inline
42 SYMBOL: tag-handler-word
45 CREATE tag-handler-word set
46 H{ } clone tag-handlers set ; parsing
48 : (TAG:) ( name quot -- ) swap tag-handlers get set-at ;
57 tag-handlers get >alist [ >r dup name-tag r> case ] curry
58 (( tag -- )) define-declared ; parsing