]> gitweb.factorcode.org Git - factor.git/blob - basis/fixups/fixups.factor
factor: trim using lists
[factor.git] / basis / fixups / fixups.factor
1 ! Copyright (C) 2021 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs continuations kernel sequences
4 vocabs vocabs.parser ;
5 IN: fixups
6
7 CONSTANT: vocab-renames {
8     { "math.intervals" { "intervals" "0.99" } }
9     { "math.ranges" { "ranges" "0.99" } }
10     { "unicode.collation" { "unicode" "0.99" } }
11 }
12
13 CONSTANT: word-renames {
14     { "lines" { "io:read-lines" "0.99" } }
15     { "words" { "splitting:split-words" "0.99" } }
16     { "contents" { "io:read-contents" "0.99" } }
17     { "exists?" { "io.files:file-exists?" "0.99" } }
18     { "string-lines" { "splitting:split-lines" "0.99" } }
19     { "[-inf,a)" { "math.intervals:[-inf,b)" "0.99" } }
20     { "[-inf,a]" { "math.intervals:[-inf,b]" "0.99" } }
21     { "(a,b)" { "ranges:(a..b)" "0.99" } }
22     { "(a,b]" { "ranges:(a..b]" "0.99" } }
23     { "[a,b)" { "ranges:[a..b)" "0.99" } }
24     { "[a,b]" { "ranges:[a..b]" "0.99" } }
25     { "[0,b)" { "ranges:[0..b)" "0.99" } }
26     { "[0,b]" { "ranges:[0..b]" "0.99" } }
27     { "[1,b)" { "ranges:[1..b)" "0.99" } }
28     { "[1,b]" { "ranges:[1..b]" "0.99" } }
29     { "assoc-merge" { "assocs.extras:assoc-collect" "0.99" } }
30     { "assoc-merge!" { "assocs.extras:assoc-collect!" "0.99" } }
31     { "peek-from" { "modern.html:peek1-from" "0.99" } }
32     { "in?" { "interval-sets:interval-in?" "0.99" } }
33     { "substitute" { "regexp.classes:(substitute)" "0.99" } }
34     { "combine" { "sets:union-all" "0.99" } }
35     { "refine" { "sets:intersect-all" "0.99" } }
36     { "read-json-objects" { "json.reader:read-json" "0.99" } }
37     { "init-namespaces" { "namespaces:init-namestack" "0.99" } }
38     { "iota" { "sequences:<iota>" ".98" } }
39 }
40
41 : compute-assoc-fixups ( continuation name assoc -- seq )
42     swap '[ drop _ = ] assoc-filter [
43         drop { }
44     ] [
45         swap '[
46             first2 dupd first2
47             " in Factor " glue " renamed to " glue "Fixup: " prepend
48             swap drop no-op-restart
49             _ <restart>
50         ] map
51     ] if-empty ;
52
53 GENERIC: compute-fixups ( continuation error -- seq )
54
55 M: object compute-fixups
56     [ error>> compute-fixups ] [ 3drop { } ] recover ;
57
58 M: f compute-fixups 2drop { } ;
59
60 M: no-vocab compute-fixups
61     [ name>> vocab-renames compute-assoc-fixups ] [ drop { } ] if* ;
62
63 M: no-word-error compute-fixups
64     [ name>> word-renames compute-assoc-fixups ] [ drop { } ] if* ;