]> gitweb.factorcode.org Git - factor.git/blob - core/source-files/errors/errors.factor
Make source file error types a bit more extensible
[factor.git] / core / source-files / errors / errors.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs kernel math.order sorting sequences definitions
4 namespaces arrays ;
5 IN: source-files.errors
6
7 TUPLE: source-file-error error asset file line# ;
8
9 : sort-errors ( errors -- alist )
10     [ [ [ line#>> ] compare ] sort ] { } assoc-map-as sort-keys ;
11
12 : group-by-source-file ( errors -- assoc )
13     H{ } clone [ [ push-at ] curry [ dup file>> ] prepose each ] keep ;
14
15 GENERIC: source-file-error-type ( error -- type )
16
17 : <definition-error> ( error definition class -- source-file-error )
18     new
19         swap
20         [ >>asset ]
21         [
22             where [ first2 ] [ "<unknown file>" 0 ] if*
23             [ >>file ] [ >>line# ] bi*
24         ] bi
25         swap >>error ; inline
26
27 : delete-file-errors ( seq file type -- )
28     [
29         [ swap file>> = ] [ swap source-file-error-type = ]
30         bi-curry* bi and not
31     ] 2curry filter-here ;
32
33 SYMBOL: source-file-error-types
34
35 source-file-error-types [ V{ } clone ] initialize
36
37 : error-types ( -- seq ) source-file-error-types get keys ;
38
39 : define-error-type ( type icon quot -- )
40     2array swap source-file-error-types get set-at ;
41
42 : error-icon-path ( type -- icon )
43     source-file-error-types get at first ;
44
45 : all-errors ( -- errors )
46     source-file-error-types get
47     [ second second call( -- seq ) ] map
48     concat ;