-USING: assocs continuations help.markup help.syntax parser sequences strings
-words vocabs ;
+USING: assocs continuations help.markup help.syntax parser quotations
+sequences strings words vocabs ;
IN: vocabs.parser
ARTICLE: "word-search-errors" "Word lookup errors"
{ $notes "This word is used to implement " { $link POSTPONE: RENAME: } "." } ;
HELP: use-words
-{ $values { "assoc" assoc } }
+{ $values { "words" assoc } }
{ $description "Adds an assoc mapping word names to words to the current manifest." } ;
HELP: unuse-words
-{ $values { "assoc" assoc } }
+{ $values { "words" assoc } }
{ $description "Removes an assoc mapping word names to words from the current manifest." } ;
+HELP: with-words
+{ $values { "words" assoc } { "quot" quotation } }
+{ $description "Calls a quotation with the words added to the current manifest, removing them from the manifest afterwards and properly handling any errors and restarts." }
+;
+
HELP: ambiguous-use-error
{ $error-description "Thrown when a word name referenced in source file is available in more than one vocabulary in the manifest. Such cases must be explicitly disambiguated using " { $link POSTPONE: FROM: } ", " { $link POSTPONE: EXCLUDE: } ", " { $link POSTPONE: QUALIFIED: } ", or " { $link POSTPONE: QUALIFIED-WITH: } "." } ;
: add-renamed-word ( word vocab new-name -- )
<rename> qualified-vocabs push ;
-: use-words ( assoc -- )
+: use-words ( words -- )
<extra-words> qualified-vocabs push ;
-: unuse-words ( assoc -- )
+: unuse-words ( words -- )
<extra-words> qualified-vocabs remove! drop ;
-: with-words ( assoc quot -- )
- '[ use-words @ ] over '[ _ unuse-words ] finally ; inline
+DEFER: with-words
+
+<PRIVATE
+
+: ?restart-with-words ( words error -- * )
+ dup condition? [
+ [ error>> ]
+ [ restarts>> rethrow-restarts ]
+ [ continuation>> '[ _ _ continue-with ] with-words ] tri
+ ] [ nip rethrow ] if ;
+
+PRIVATE>
+
+: with-words ( words quot -- )
+ [ over '[ _ use-words @ _ unuse-words ] ]
+ [ drop dup '[ _ unuse-words _ swap ?restart-with-words ] ]
+ 2bi recover ; inline
TUPLE: ambiguous-use-error name words ;