| 
									
										
										
										
											2008-08-27 20:27:06 -04:00
										 |  |  | USING: accessors sequences assocs kernel quotations namespaces | 
					
						
							| 
									
										
										
										
											2008-12-02 01:25:23 -05:00
										 |  |  | xml.data xml.utilities combinators macros parser lexer words fry ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | IN: xmode.utilities | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 21:31:55 -05:00
										 |  |  | : implies ( x y -- z ) [ not ] dip or ; inline
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-27 20:27:06 -04:00
										 |  |  | : child-tags ( tag -- seq ) children>> [ tag? ] filter ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : map-find ( seq quot -- result elt )
 | 
					
						
							|  |  |  |     f -rot
 | 
					
						
							| 
									
										
										
										
											2008-12-02 01:25:23 -05:00
										 |  |  |     '[ nip @ dup ] find
 | 
					
						
							|  |  |  |     [ [ drop f ] unless ] dip ; inline
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : tag-init-form ( spec -- quot )
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |         { [ dup quotation? ] [ [ object get tag get ] prepose ] } | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  |         { [ dup length 2 = ] [ | 
					
						
							| 
									
										
										
										
											2008-12-02 01:25:23 -05:00
										 |  |  |             first2 '[ | 
					
						
							|  |  |  |                 tag get children>string | 
					
						
							|  |  |  |                 _ [ execute ] when* object get _ execute
 | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  |         ] } | 
					
						
							|  |  |  |         { [ dup length 3 = ] [ | 
					
						
							| 
									
										
										
										
											2008-12-02 01:25:23 -05:00
										 |  |  |             first3 '[ | 
					
						
							|  |  |  |                 _ tag get at
 | 
					
						
							|  |  |  |                 _ [ execute ] when* object get _ execute
 | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  |         ] } | 
					
						
							|  |  |  |     } cond ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-tag-initializer ( tag obj quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-04-26 00:17:08 -04:00
										 |  |  |     [ object set tag set ] prepose with-scope ; inline
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | MACRO: (init-from-tag) ( specs -- )
 | 
					
						
							|  |  |  |     [ tag-init-form ] map concat [ ] like
 | 
					
						
							|  |  |  |     [ with-tag-initializer ] curry ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : init-from-tag ( tag tuple specs -- tuple )
 | 
					
						
							| 
									
										
										
										
											2008-12-02 01:25:23 -05:00
										 |  |  |     over [ (init-from-tag) ] dip ; inline
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: tag-handlers | 
					
						
							|  |  |  | SYMBOL: tag-handler-word | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <TAGS: | 
					
						
							|  |  |  |     CREATE tag-handler-word set
 | 
					
						
							|  |  |  |     H{ } clone tag-handlers set ; parsing | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 03:14:14 -04:00
										 |  |  | : (TAG:) ( name quot -- ) swap tag-handlers get set-at ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : TAG: | 
					
						
							|  |  |  |     scan parse-definition | 
					
						
							|  |  |  |     (TAG:) ; parsing | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : TAGS> | 
					
						
							|  |  |  |     tag-handler-word get
 | 
					
						
							| 
									
										
										
										
											2008-08-27 20:27:06 -04:00
										 |  |  |     tag-handlers get >alist [ >r dup main>> r> case ] curry
 | 
					
						
							| 
									
										
										
										
											2008-06-15 04:25:41 -04:00
										 |  |  |     define ; parsing |