]> gitweb.factorcode.org Git - factor.git/commitdiff
vocabs.parser: fix with-words to be properly restartable.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 17 Dec 2020 00:03:55 +0000 (16:03 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 17 Dec 2020 00:03:55 +0000 (16:03 -0800)
We want with-words to unuse-words when a restart is provided but
not restarted, but if restarted, we need to use-words again and
then unuse-words.

core/vocabs/parser/parser-docs.factor
core/vocabs/parser/parser.factor

index 85f5614823103fe33c5b90125064e66a75699ed6..a17c991c33257a4156a042981caf1f0413314727 100644 (file)
@@ -1,5 +1,5 @@
-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"
@@ -162,13 +162,18 @@ HELP: add-renamed-word
 { $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: } "." } ;
 
index cec44020512964b0acb6b65607fd96efa5227dd2..a1bd8a97dcb8b4841dd67f35dfb2dd55ba59d304 100644 (file)
@@ -169,14 +169,29 @@ TUPLE: rename word vocab words ;
 : 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 ;