1 ! Copyright (C) 2005, 2009 Daniel Ehrenberg, Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: xml.tokenize xml.data xml.state kernel sequences ascii
4 fry xml.errors combinators hashtables namespaces xml.entities
8 : take-word ( -- string )
9 [ get-char blank? ] take-until ;
11 : take-decl-contents ( -- first second )
12 pass-blank take-word pass-blank ">" take-string ;
14 : take-element-decl ( -- element-decl )
15 take-decl-contents <element-decl> ;
17 : take-attlist-decl ( -- attlist-decl )
18 take-decl-contents <attlist-decl> ;
20 : take-notation-decl ( -- notation-decl )
21 take-decl-contents <notation-decl> ;
23 : take-until-one-of ( seps -- str sep )
24 '[ get-char _ member? ] take-until get-char ;
26 : take-system-id ( -- system-id )
27 parse-quote <system-id> close ;
29 : take-public-id ( -- public-id )
30 parse-quote parse-quote <public-id> close ;
33 directive comment instruction ;
35 : (take-external-id) ( token -- external-id )
37 { "SYSTEM" [ take-system-id ] }
38 { "PUBLIC" [ take-public-id ] }
42 : take-external-id ( -- external-id )
43 take-word (take-external-id) ;
45 : only-blanks ( str -- )
46 [ blank? ] all? [ bad-decl ] unless ;
47 : take-entity-def ( var -- entity-name entity-def )
49 take-word pass-blank get-char {
50 { CHAR: ' [ parse-quote ] }
51 { CHAR: " [ parse-quote ] }
52 [ drop take-external-id ]
54 ] dip '[ swap _ [ ?set-at ] change ] 2keep ;
56 : take-entity-decl ( -- entity-decl )
58 { CHAR: % [ next pass-blank pe-table take-entity-def t ] }
59 [ drop extra-entities take-entity-def f ]
60 } case close <entity-decl> ;
62 : take-inner-directive ( string -- directive )
64 { "ELEMENT" [ take-element-decl ] }
65 { "ATTLIST" [ take-attlist-decl ] }
66 { "ENTITY" [ take-entity-decl ] }
67 { "NOTATION" [ take-notation-decl ] }