]> gitweb.factorcode.org Git - factor.git/commitdiff
fixups: Initial commit of a code migration feature.
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 30 Dec 2021 05:14:40 +0000 (23:14 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 30 Dec 2021 08:25:26 +0000 (02:25 -0600)
Fixups inspect an error thrown and eventually offer restarts or
messages that something changed and in which version of Factor.

For instance, if we renamed `lines` to `read-lines` in .99,
the restart for `lines not found` will offer that it was
renamed to `read-lines`.

basis/fixups/authors.txt [new file with mode: 0644]
basis/fixups/fixups.factor [new file with mode: 0644]

diff --git a/basis/fixups/authors.txt b/basis/fixups/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/fixups/fixups.factor b/basis/fixups/fixups.factor
new file mode 100644 (file)
index 0000000..b73788d
--- /dev/null
@@ -0,0 +1,59 @@
+! Copyright (C) 2021 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs continuations formatting kernel
+sequences vocabs vocabs.parser ;
+IN: fixups
+
+CONSTANT: vocab-renames {
+    { "math.intervals" { "intervals" ".99" } }
+    { "math.ranges" { "ranges" ".99" } }
+    { "asdfasdf" { "asdfasdf2" ".99" } }
+}
+
+CONSTANT: word-renames {
+    { "lines" { "io:read-lines" ".99" } }
+    { "lines" { "splitting:split-lines" ".99" } }
+    { "words" { "splitting:split-words" ".99" } }
+    { "contents" { "io:read-contents" ".99" } }
+    { "exists?" { "io.files:file-exists?" ".99" } }
+    { "string-lines" { "splitting:split-lines" ".99" } }
+    { "split-lines" { "documents.private:?split-lines" ".99" } }
+    { "[-inf,a)" { "math.intervals:[-inf,b)" ".99" } }
+    { "[-inf,a]" { "math.intervals:[-inf,b]" ".99" } }
+    { "(a,b)" { "math.ranges:(a..b)" ".99" } }
+    { "(a,b]" { "math.ranges:(a..b]" ".99" } }
+    { "[a,b)" { "math.ranges:[a..b)" ".99" } }
+    { "[a,b]" { "math.ranges:[a..b]" ".99" } }
+    { "assoc-merge" { "assocs.extras:assoc-collect" ".99" } }
+    { "assoc-merge!" { "assocs.extras:assoc-collect!" ".99" } }
+    { "peek-from" { "modern.html:peek1-from" ".99" } }
+    { "in?" { "interval-sets:interval-in?" ".99" } }
+    { "substitute" { "regexp.classes:(substitute)" ".99" } }
+    { "combine" { "sets:union-all" ".99" } }
+    { "refine" { "sets:intersect-all" ".99" } }
+    { "read-json-objects" { "json.reader:read-json" ".99" } }
+}
+
+: compute-assoc-fixups ( continuation name assoc -- seq )
+    swap '[ drop _ = ] assoc-filter [
+        drop { }
+    ] [
+        swap '[
+            first2 dupd first2 "Fixup: `%s` got renamed to `%s` in %s" sprintf
+            swap drop f
+            _ <restart>
+        ] map
+    ] if-empty ;
+
+GENERIC: compute-fixups ( continuation error -- seq )
+
+M: object compute-fixups
+    error>> compute-fixups ;
+
+M: f compute-fixups 2drop { } ;
+
+M: no-vocab compute-fixups
+    name>> vocab-renames compute-assoc-fixups ;
+
+M: no-word-error compute-fixups
+    name>> word-renames compute-assoc-fixups ;