 USING: xmode.loader xmode.utilities xmode.rules namespaces
 strings splitting assocs sequences kernel io.files xml memoize
 words globs combinators io.encodings.utf8 io.pathnames sorting
-accessors xml.data xml.traversal xml.syntax ;
+accessors regexp unicode.case xml.data xml.traversal
+xml.syntax ;
 IN: xmode.catalog
 
 TUPLE: mode file file-name-glob first-line-glob ;

: reset-modes ( -- )
    \ (load-mode) reset-memoized ;

: ?glob-matches ( string glob/f -- ? )
    dup [ glob-matches? ] [ 2drop f ] if ;

: suitable-mode? ( file-name first-line mode -- ? )
    [ nip ] 2keep first-line-glob>> ?glob-matches
    [ 2drop t ] [ file-name-glob>> ?glob-matches ] if ;

: ?find-mode ( file-name first-line -- mode/f )
    [ file-name ] dip

            { "FILE_NAME_GLOB" f file-name-glob<< }
            { "FIRST_LINE_GLOB" f first-line-glob<< }
        } init-from-tag
        [ [ >case-fold <glob> ] [ f ] if* ] change-file-name-glob
        [ [ >case-fold <glob> ] [ f ] if* ] change-first-line-glob
    ] dip
    rot set-at ;

