1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel strings assocs sequences hashtables
4 sorting unicode.case unicode.categories sets ;
7 ! Based on org.gjt.sp.jedit.syntax.KeywordMap
8 TUPLE: keyword-map no-word-sep ignore-case? assoc ;
10 : <keyword-map> ( ignore-case? -- map )
15 : invalid-no-word-sep ( keyword-map -- ) f >>no-word-sep drop ;
17 : handle-case ( key keyword-map -- key assoc )
18 [ ignore-case?>> [ >upper ] when ] [ assoc>> ] bi ;
20 M: keyword-map assoc-size
23 M: keyword-map at* handle-case at* ;
26 [ handle-case set-at ] [ invalid-no-word-sep ] bi ;
28 M: keyword-map clear-assoc
29 [ assoc>> clear-assoc ] [ invalid-no-word-sep ] bi ;
34 : (keyword-map-no-word-sep) ( assoc -- str )
35 keys concat [ alpha? not ] filter prune natural-sort ;
37 : keyword-map-no-word-sep* ( keyword-map -- str )
38 dup no-word-sep>> [ ] [
39 dup (keyword-map-no-word-sep) >>no-word-sep
40 keyword-map-no-word-sep*
43 INSTANCE: keyword-map assoc