Make the require-hook throw an error if the vocabulary does not exist in the dictionary or on disk. Move require docs to vocabs. Add unit tests for require. Fixes #339.
parent
ddb06ab6cb
commit
f6353e17cd
|
@ -73,8 +73,7 @@ ABOUT: "vocabs.loader"
|
|||
|
||||
HELP: load-vocab
|
||||
{ $values { "name" "a string" } { "vocab" "a hashtable or " { $link f } } }
|
||||
{ $description "Outputs a named vocabulary. If the vocabulary does not exist, throws a restartable " { $link no-vocab } " error. If the user invokes the restart, this word outputs " { $link f } "." }
|
||||
{ $error-description "Thrown by " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " when a given vocabulary does not exist. Vocabularies must be created by " { $link POSTPONE: IN: } " before being used." } ;
|
||||
{ $description "Attempts to load a vocabulary from disk, or looks up the vocabulary in the dictionary, and then outputs that vocabulary object." } ;
|
||||
|
||||
HELP: vocab-main
|
||||
{ $values { "vocab-spec" "a vocabulary specifier" } { "main" word } }
|
||||
|
@ -113,11 +112,6 @@ HELP: reload
|
|||
{ $description "Reloads the source code and documentation for a vocabulary." }
|
||||
{ $errors "Throws a " { $link no-vocab } " error if the vocabulary does not exist on disk." } ;
|
||||
|
||||
HELP: require
|
||||
{ $values { "vocab" "a vocabulary specifier" } }
|
||||
{ $description "Loads a vocabulary if it has not already been loaded." }
|
||||
{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
|
||||
|
||||
HELP: require-when
|
||||
{ $values { "if" "a sequence of vocabulary specifiers" } { "then" "a vocabulary specifier" } }
|
||||
{ $description "Loads the " { $snippet "then" } " vocabulary if it is not loaded and all of the " { $snippet "if" } " vocabulary is. If some of the " { $snippet "if" } " vocabularies are not loaded now, but they are later, then the " { $snippet "then" } " vocabulary will be loaded along with the final one." }
|
||||
|
|
|
@ -159,8 +159,12 @@ PRIVATE>
|
|||
[
|
||||
dup vocab-name blacklist get at*
|
||||
[ rethrow ]
|
||||
[ drop dup find-vocab-root [ (require) ] [ drop ] if ]
|
||||
if
|
||||
[
|
||||
drop dup find-vocab-root
|
||||
[ (require) ]
|
||||
[ dup lookup-vocab [ drop ] [ no-vocab ] if ]
|
||||
if
|
||||
] if
|
||||
] require-hook set-global
|
||||
|
||||
M: vocab-spec where vocab-source-path dup [ 1 2array ] when ;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
USING: help.markup help.syntax strings words compiler.units ;
|
||||
USING: help.markup help.syntax strings words compiler.units
|
||||
vocabs.loader ;
|
||||
IN: vocabs
|
||||
|
||||
ARTICLE: "vocabularies" "Vocabularies"
|
||||
|
@ -79,6 +80,11 @@ HELP: forget-vocab
|
|||
HELP: require-hook
|
||||
{ $var-description { $quotation "( name -- )" } " which loads a vocabulary. This quotation is called by " { $link require } ". The default value should not need to be changed; this functionality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
|
||||
|
||||
HELP: require
|
||||
{ $values { "object" "a vocabulary specifier" } }
|
||||
{ $description "Loads a vocabulary if it has not already been loaded. Throws an error if the vocabulary does not exist on disk or in the dictionary." }
|
||||
{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
|
||||
|
||||
HELP: words-named
|
||||
{ $values { "str" string } { "seq" "a sequence of words" } }
|
||||
{ $description "Outputs a sequence of all words named " { $snippet "str" } " from the set of currently-loaded vocabularies." } ;
|
||||
|
|
|
@ -29,3 +29,9 @@ IN: vocabs.tests
|
|||
[ 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
|
||||
|
||||
[ "sojoijsaoifjsthisdoesntexistomgomgomgplznodontexist" require ]
|
||||
[ no-vocab? ] must-fail-with
|
||||
|
||||
[ "letstrythisagainnooooooyoucantexistnoooooo" load-vocab ]
|
||||
[ no-vocab? ] must-fail-with
|
||||
|
|
Loading…
Reference in New Issue