dup vocab-roots get member? [ vocab-root-required ] unless ;\r
\r
: ensure-vocab-root/prefix ( root prefix -- root prefix )\r
- [ ensure-vocab-root ] [ forbid-absolute-path ] bi* ;\r
+ [ ensure-vocab-root ] [ check-vocab-name ] bi* ;\r
\r
: (child-vocabs) ( root prefix -- vocabs )\r
ensure-vocab-root/prefix\r
: vocab-dir ( vocab -- dir )
vocab-name { { CHAR: . CHAR: / } } substitute ;
-ERROR: absolute-path-forbidden path ;
-
-: forbid-absolute-path ( str -- str )
- dup absolute-path? [ absolute-path-forbidden ] when ;
-
: append-vocab-dir ( vocab str/f -- path )
- [ vocab-name forbid-absolute-path "." split ] dip
+ [ vocab-name "." split ] dip
[ [ dup last ] dip append suffix ] when*
"/" join ;
[ t ] [ "" "io.files" child-vocab? ] unit-test
[ t ] [ "io" "io.files" child-vocab? ] unit-test
[ f ] [ "io.files" "io" child-vocab? ] unit-test
+
+[ "foo/bar" create-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo\\bar" create-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo:bar" create-vocab ] [ bad-vocab-name? ] must-fail-with
+[ 3 create-vocab ] [ bad-vocab-name? ] must-fail-with
+[ f create-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "a b" create-vocab ] [ bad-vocab-name? ] must-fail-with
+
+[ "foo/bar" lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo\\bar" lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo:bar" lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ 3 lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ f lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "a b" lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+
+[ "foo/bar" >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo\\bar" >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "foo:bar" >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ 3 >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ f >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
+[ "a b" >vocab-link lookup-vocab ] [ bad-vocab-name? ] must-fail-with
swap >>name
H{ } clone >>words ;
+ERROR: bad-vocab-name name ;
+
+: check-vocab-name ( name -- name )
+ dup string? [ bad-vocab-name ] unless
+ dup ":/\\ " intersects? [ bad-vocab-name ] when ;
+
TUPLE: vocab-link name ;
C: <vocab-link> vocab-link
M: vocab-link vocab-name name>> ;
-M: string vocab-name ;
+M: object vocab-name check-vocab-name ;
GENERIC: lookup-vocab ( vocab-spec -- vocab )
: notify-vocab-observers ( -- )
vocab-observers get [ vocabs-changed ] each ;
-ERROR: bad-vocab-name name ;
-
-: check-vocab-name ( name -- name )
- dup string? [ bad-vocab-name ] unless ;
-
: create-vocab ( name -- vocab )
check-vocab-name
dictionary get [ <vocab> ] cache
M: vocab-spec >vocab-link ;
-M: string >vocab-link dup lookup-vocab [ ] [ <vocab-link> ] ?if ;
+M: object >vocab-link dup lookup-vocab [ ] [ <vocab-link> ] ?if ;
: forget-vocab ( vocab -- )
[ words forget-all ]